Regular Expression that matchs more than one condtion

  • Thread starter Thread starter Earl Teigrob
  • Start date Start date
E

Earl Teigrob

I am parsing HTML and have source text like this

<A,A>

that I would like to retreive all of the "A"s from using an expression like

<[^>]*?(?<content>A)[^>]*?>

Even though this will technically match both A's, it only returns the first
one. How can I return both "A"s

Thanks

Earl
 
Try this:

<((?<content>A)|[^>])*>

You can iterate through the Captures collection of the named group 'content'
to get each A.


Alternatively, I think you could use:

(?<=<[^>]*)A(?=[^>]*)

With this, you iterate through the Matches in MatchCollection to get each A.



Brian Davis
http://www.knowdotnet.com
 
Thanks Brian, That worked perfectly. In fact, I decided I had better read
my regular expressions book so I can really get a grip on this stuff

Earl
Brian Davis said:
Try this:

<((?<content>A)|[^>])*>

You can iterate through the Captures collection of the named group 'content'
to get each A.


Alternatively, I think you could use:

(?<=<[^>]*)A(?=[^>]*)

With this, you iterate through the Matches in MatchCollection to get each A.



Brian Davis
http://www.knowdotnet.com




Earl Teigrob said:
I am parsing HTML and have source text like this

<A,A>

that I would like to retreive all of the "A"s from using an expression like

<[^>]*?(?<content>A)[^>]*?>

Even though this will technically match both A's, it only returns the first
one. How can I return both "A"s

Thanks

Earl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top