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

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

Moderator: General Moderators

Post Reply
Torrodon
Forum Newbie
Posts: 4
Joined: Sun Jun 07, 2009 7:24 am

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

Post 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.
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

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

Post by ridgerunner »

Just convert the greedy .+ to lazy .+? like so:

Code: Select all

@<a[^>]*classname[^>]*>.+?</a>@i'
Torrodon
Forum Newbie
Posts: 4
Joined: Sun Jun 07, 2009 7:24 am

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

Post by Torrodon »

Thank you it worked!
Post Reply