Page 1 of 1

how to make [^.....] for sting instead for chars...

Posted: Fri Nov 13, 2009 11:06 pm
by Torrodon
How to make my regexp to catch the following strings:
<A class="classname" href="http://domain/subfolders">some text <BR /> more text</A>
<A href="http://domain/subfolders" class=classname>some text <BR /> more text</A>
<A href="http://domain/subfolders" class="classname">some text more text</A>
but not to catch the following:
<A class="classname" href="http://domain/subfolders">some text more text</A>more text</A>

to catch the first 3 strings i tried this:
'@<a[^>]*classname[^>]*>.+</a>@i'
Unfortunately it catches the second one too. I cannot figure it how to replace .+ so <br /> (or any other tag) to pass except </a> tag.

Re: how to make [^.....] for sting instead for chars...

Posted: Sat Nov 14, 2009 12:49 pm
by ridgerunner
Just convert the greedy .+ to lazy .+? like so:

Code: Select all

@<a[^>]*classname[^>]*>.+?</a>@i'

Re: how to make [^.....] for sting instead for chars...

Posted: Sun Nov 15, 2009 12:29 am
by Torrodon
Thank you it worked!