Am I doing something wrong?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Am I doing something wrong?

Post by prometheuzz »

GeertDD wrote:...
One more argument to go for the strpos() check instead of trying to make the regex do all the work. ...
Couldn't agree more with you!
nirali35
Forum Newbie
Posts: 6
Joined: Mon May 26, 2008 1:24 pm

Re: Am I doing something wrong?

Post by nirali35 »

Thanks a lot guys :)
I have solved the problem, and more importantly, I have learned many *good* things!! :)
GeertDD wrote: Yeah, you are probably right. One more argument to go for the strpos() check instead of trying to make the regex do all the work. Why? Because you don't know for sure which part comes first within the query string: task or itemid? The regex would have to check both possibilities. Let me just quickly try to cook something up (not tested), just as an example of how ugly it gets. ;)

Code: Select all

$regex = '/<a\s++href="([^"]*\b(?:task=view\b[^"]+\bitemid=123|itemid=123\b[^"]+\btask=view)\b[^"]*+)"[^>]*+>([^<]++)/i';
Post Reply