Forum Moderators: coopster
[($[0-9]+<font size="-2">US</font>)]
It's supposed to find this:
($57<font size="-2">US</font>)
But it's not finding the last character (closing parenthesis so only this is found:
($57<font size="-2">US</font>
I want to remove that code from 100's of pages, but it defeats the purpose if a ')' is left in it's place on the pages. Anyone know if a closing parenthesis is some kind of escaped character or special character?
Regards,
James...
[edited by: eelixduppy at 2:41 am (utc) on Oct. 25, 2007]
[edit reason] disabled smileys [/edit]
In the regular expression the () are used to define a captured pattern. So you may well need to use something along the lines of -
(\($[0-9]+<font size="-2">US</font>\))
Have a look at the PCRE pattern syntax [uk3.php.net] for the full description.
[($[0-9]+<font size="-2">US</font>)] (this is exactly as i put it in the search box and it finds all instances but only HIGHLIGHTS this:
($29<font size="-2">US</font>
^^^
So it misses the closing parenthesis which defeats the purposes of finding all instances to remove it.
Any thoughts?
James...
[edited by: eelixduppy at 3:46 pm (utc) on Oct. 25, 2007]
[edit reason] disabled smileys [/edit]
The $ that you have in the string, if not escaped will mean the end of the string to search. So that will need escaping.
So you can get rid of the []'s as you are not looking for a character class.
Also dont believe everything that Dreamweaver tells you...like most products if it doesnt work then the problem is not with the manual, its with the automated system you are using to generate the code.
I have tested this and it works. So hopefully it is what you are after.
$pattern = '%^(\(\$[0-9]{1,2}<font size="\-2">US</font>\))+$%';
$sub = '($57<font size="-2">US</font>)';
if (preg_match($pattern, $sub) == 1){
echo 'Working<br />';
}
else{
echo 'You suck<br />';
}
[edited by: eelixduppy at 2:10 pm (utc) on Oct. 26, 2007]
[edit reason] disabled smileys [/edit]
Take your text:
($54<font size="-2">US</font>)
Escape everything apart from a-z and 0-9:
\(\$54\<font\ size\=\"\-2\"\>US\<\/font\>\)
Change the variable bit into a wildcard:
\(\$[0-9]+\<font\ size\=\"\-2\"\>US\<\/font\>\)
Remember, surround it with some delimiters before testing, I prefer /:
/\(\$[0-9]+\<font\ size\=\"\-2\"\>US\<\/font\>\)/
[edited by: eelixduppy at 2:11 pm (utc) on Oct. 26, 2007]
[edit reason] disabled smileys [/edit]