Forum Moderators: coopster

Message Too Old, No Replies

Preg match but stop with multiple characters

         

wesg

3:00 am on Jun 1, 2009 (gmt 0)

10+ Year Member



I'm doing some preg programming, but I need to capture text that doesn't include the </a> anchor tag. I know about the ([^/]+) wildcard, but how I can use this with multiple characters? I want to have a match that starts with my string, but stops at the first </a> tag it encounters.

Any suggestions?

idfer

4:04 am on Jun 1, 2009 (gmt 0)

10+ Year Member



You want to use the quantifier minimizer, question mark:

if a quantifier is followed by a question mark, then it ceases to be greedy, and instead matches the minimum number of times possible

So try: (.*?)</a>

wesg

11:06 pm on Jun 7, 2009 (gmt 0)

10+ Year Member



Thanks, that seems to work, but I still can't get it working exactly right. Something like ([^(</a>)]+) would work better, but the ^ character doesn't seem to work with a group.

Suggestions?

[edited by: eelixduppy at 10:17 pm (utc) on June 8, 2009]
[edit reason] disabled smileys [/edit]