Regex Question

  • Thread starter Thread starter NotYetaNurd
  • Start date Start date
N

NotYetaNurd

I have a text like this
<a href=aaaa>something </a><a href=aaaa>something </a><a href=aaaa>something
</a><a href=aaaa>something </a><a href=aaaa>something </a>
i have to extract each "<a href=aaaa>something </a> "out i did something
like this
<A[^>]*>.*</A>

but it returns the whole string rather than individual "<a
href=aaaa>something </a>"

Where am i going wrong.....
 
Try the following expression:

<A[^>]*>.*?</A>

Notice the question mark to indicate a "lazy" matching so that it stops at
the first occurence of </A> and not at the last on the line.


Arild
 
The .* term is gobbling up the whole string. Use .*? (non-greedy gobble) or
just [^<]*.

There is a tradeoff, as always. .*? is slightly more expensive at
run-time, but it's a little clearer.

Jon
 
Back
Top