PDA

View Full Version : RegEx Expression Trouble


The Geek
11-13-2005, 08:38 PM
HowdA All,

I am hoping one of your gurus can help we out with a small regex problem.

What I want to do is find all occurrences of "my test" in the following string:

$text = "my test<ul><li>my test</li></ul> <b>my test</b> my test <i>my test</i> <!--nope--> my test";

Easy huh? However the real catch is that I want to find ALL of them EXCEPT <!--nope--> my test

So this is what im doing now:

#(\b((\s|<li>|<strong>|<b>|<i>)my test)s?\b)#im


Which catches all of them. How can I do it so it explicity DOESNT catch the last one?

Thanks all!

Marco van Herwaarden
11-13-2005, 08:42 PM
Ask your wife. :D
Sorry eyes are already giving me a hard time in keeping them open. If you would have posted this in the morning i would have given it a go.

Might want to wait for Dean to reply.

The Geek
11-13-2005, 08:47 PM
Mrs Geek is too busy trying to find Regex for her new 'Get Geek to Wash Car Module 1.05'

Happily I have stuck it in a really good place where she should never find it :)

Any help when you can is appreciated

Comeon guys! Sont you want a cookie?

http://www.gift-baskets-4u.com/images/Cookies/Chocolate%20Cookie%20With%20White%20Chocolate%20Ch ips%20.jpg

AAAAAAAAAAAAAARGGGGGGGGGGGGGGGGGGGGGG I FREAKING HATE AUTOMERGE.


How the hell are you supposed to bump something with auto merge?

I need to find a way to get around this.

The Geek
11-19-2005, 01:29 PM
Please, for the love of PETE.... someone throw me a bone here.

Marco van Herwaarden
11-19-2005, 01:36 PM
Does the <!-- nope> also have a closing tag, or is everything after that ignored?

The Geek
11-19-2005, 02:57 PM
Hey Marco,

The tag was <!--nope-->, however I THINK I have found the solution like this:


#(\b((?<=\s|<li>|<strong>|<b>|<i>)(?<!nope--> )my test)s?\b)#im


Basically, I wasnt properly doing a look ahead assertion.

Thanks for your help.

Andreas
11-19-2005, 03:33 PM
Yep, look ahead is the way to go.