By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,668 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,668 IT Pros & Developers. It's quick & easy.

Regex Question

P: n/a
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.....

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"NotYetaNurd" <No*********@Matrix.com> wrote in message
news:u6**************@TK2MSFTNGP11.phx.gbl...
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.....

Nov 13 '05 #2

P: n/a

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

"NotYetaNurd" <No*********@Matrix.com> wrote in message
news:u6**************@TK2MSFTNGP11.phx.gbl...
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.....

Nov 13 '05 #3

P: n/a
Thanks You ...
"NotYetaNurd" <No*********@Matrix.com> wrote in message
news:u6**************@TK2MSFTNGP11.phx.gbl...
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.....

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.