Welcome to WebmasterWorld Guest from 18.104.22.168 , register , login , search , subscribe , help , library , PubCon , announcements , recent posts , open posts Subscribe and Support WebmasterWorld
why this regex doesn't work? zozzen msg:3609371 7:15 pm on Mar 24, 2008 (gmt 0) Hi, I'm trying to grab the content like this with preg_match or eregi_replace:
The content is like this:
<span class=a>.....</span> <a class=fl href="www.example.com">....</a> <table>....</table> <a class=fl href="www.example.com">....</a>
The regex i wrote:
<span class=a>(.*?)</span><a class=fl(.*?)</a>(.*?)<a class=fl(.*?)</a>
By using regex verifier software, the regex i use seems to be valid, but after executing it, it says "Unknown modifier".
Do you have any idea what happens? I've spent an hour on this, but still have no idea. Any help is highly appreciated. Thanks thanks!
eelixduppy msg:3609565 10:36 pm on Mar 24, 2008 (gmt 0)
What is the exact php code you are using with the regex--more specifically, the code for the pattern?
zozzen msg:3610980 12:41 pm on Mar 26, 2008 (gmt 0)
hi, i tried both preg_replace and eregi_replace before. The code is like this:
$output = eregi_replace("<span class=a>(.*?)</span><a class=fl(.*?)</a>(.*?)<a class=fl(.*?)</a>", "hello word", $output);
$output = preg_replace("/<span class=a>(.*?)</span><a class=fl(.*?)</a>(.*?)<a class=fl(.*?)</a>/is", "hello world", $output);
but it seems both sentences doesn't work too. very frustrated.....
Achernar msg:3611002 1:15 pm on Mar 26, 2008 (gmt 0)
Several remarks here: * in preg_replace() you must escape the "/" char in the closing html tags : <\/span> * in the example text you have a "space" between the </span> and the next <a >. The correct RE for preg_replace looks like this: "/<span class=a>(.*?)<\/span>\s*<a class=fl(.*?)<\/a>(.*?)<a class=fl(.*?)<\/a>/is" * The way the replace function work, it will replace the whole RE with "hello world". Not the (.*?).
If you need to extract some information from the code, you should use preg_match() or preg_match_all(), and work with the "matches" array.
zozzen msg:3618803 7:30 am on Apr 4, 2008 (gmt 0)
thanks a lot, achernar! I'll be more careful next time on regex. I really got mad with this.