Regex help needed
| From: | Sid | Date: | Thu, 17 Jul 2003 08:28:31 +0000 |
| Subject: | Regex help needed | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-155479@lists.php.net to get a copy of this message | ||
Hello,
Well I am doing by first reg ex operations and I am having problems which I just cannot figure out.
For example I tried
echo eregi_replace ("<tr bgcolor=\"#F8F8F1\">(\s*)<td>\s*<font
size=\"2\">\s*purchasing power parity", '%POWER%',
'<td><tr>sdsdss<tr bgcolor="#f8f8f1"><td><font
size="2">Purchasing power parity');
and this worked perfectly,
but when I chnaged that to
echo eregi_replace ("<tr bgcolor=\"#F8F8F1\">(\s*)<td>\s*<font
size=\"2\">\s*purchasing\s+power\s+parity", '%POWER%',
'<td><tr>sdsdss<tr bgcolor="#f8f8f1"><td><font
size="2">Purchasing power parity');
It does not detect the string. Srange. According to what I know, \s+ will detect a single space
also. I tried chnaging the last 2 \s+ to \s* but this did not work also.
Any ideas on this one?
As I proceed I would like the expression to detect the optional face attribute also, so I tried
echo eregi_replace ("<tr bgcolor=\"#F8F8F1\">(\s*)<td>\s*<font
size=\"2\"(\s+face=\"Verdana, Arial, Helvetica, sans-serif\"|)>\s*purchasing
power parity", '%POWER%', '<td><tr>sdsdss<tr
bgcolor="#f8f8f1" face="Verdana, Arial, Helvetica,
sans-serif"><td><font size="2">Purchasing power parity');
... and this gave me an error like
Warning: eregi_replace(): REG_EMPTY:çempty (sub)expression in D:\sid\dg\test.php on line 2
Any ideas? BTW any place where I can get started on regex? I got a perl book that explains regex,
but I have got to learn perl first (I dont know any perl)
Thanks in advance.
- Sid