my challenges with merging 2 Regex.Matches

  • Thread starter Thread starter D. Patrick
  • Start date Start date
D

D. Patrick

I'm trying to find all occurrences of either:

<font color="red">Smith</font>
or
<font color="blue">Smith</font>

inside strIn which contains a lot of HTML and lot of possible lines like
above but sometimes those lines are green. I only want the matches that
are red or blue.

I can easily do this:

Dim strMatch as string = "<font color=""red"">Smith</font>"
Dim mc as System.Text.RegularExpressions.MatchCollection = _
System.Text.regularExpressions.Regex.Matches ( strIn, strMatch )

and that works for red. But how do I either merge a red match result with a
blue match result, OR somehow use regex better so it knows to match either
red or blue in a single pattern?
 
D. Patrick said:
I'm trying to find all occurrences of either:

<font color="red">Smith</font>
or
<font color="blue">Smith</font>

inside strIn which contains a lot of HTML and lot of possible lines like
above but sometimes those lines are green. I only want the matches that
are red or blue.

I can easily do this:

Dim strMatch as string = "<font color=""red"">Smith</font>"
Dim mc as System.Text.RegularExpressions.MatchCollection = _
System.Text.regularExpressions.Regex.Matches ( strIn, strMatch )

and that works for red. But how do I either merge a red match result with
a blue match result, OR somehow use regex better so it knows to match
either red or blue in a single pattern?

"<font color=""(red)|(blue)"">Smith</font>"

Try that, untested :)

HTH,
Mythran
 
Mythran said:
"<font color=""(red)|(blue)"">Smith</font>"

Try that, untested :)

HTH,
Mythran

After testing my reply...I found that the following is probably what you
want, instead:

<font color=""(red|blue)"">Smith</font>

HTH :)

Mythran
 
Mythran said:
After testing my reply...I found that the following is probably what you
want, instead:

<font color=""(red|blue)"">Smith</font>

HTH :)

Mythran

thank you. and what about if the font string is empty, such as

color=""

how would you package the empty into the choices? like this? ...

<font color=""(red|blue|)"">Smith</font>
 
D. Patrick said:
thank you. and what about if the font string is empty, such as

color=""

how would you package the empty into the choices? like this? ...

<font color=""(red|blue|)"">Smith</font>

Possibly, test it and see :0

Mythran
 
Back
Top