Home All Groups Group Topic Archive Search About

my challenges with merging 2 Regex.Matches

Author
21 Jun 2006 3:57 PM
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?

Author
21 Jun 2006 6:14 PM
Mythran
Show quote Hide quote
"D. Patrick" <replywithinthegr***@thenotreal.com> wrote in message
news:R%dmg.3579$MF6.2782@tornado.socal.rr.com...
> 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
Author
21 Jun 2006 8:36 PM
Mythran
Show quote Hide quote
"Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message
news:OwqUG6VlGHA.4268@TK2MSFTNGP05.phx.gbl...
>
> "D. Patrick" <replywithinthegr***@thenotreal.com> wrote in message
> news:R%dmg.3579$MF6.2782@tornado.socal.rr.com...
>> 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
>

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

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

HTH :)

Mythran
Author
21 Jun 2006 11:37 PM
D. Patrick
Show quote Hide quote
"Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message
news:OD$ZiJXlGHA.3304@TK2MSFTNGP03.phx.gbl...
>
> "Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message
> news:OwqUG6VlGHA.4268@TK2MSFTNGP05.phx.gbl...
>>
>> "D. Patrick" <replywithinthegr***@thenotreal.com> wrote in message
>> news:R%dmg.3579$MF6.2782@tornado.socal.rr.com...
>>> 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
>>
>
> 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>
Author
22 Jun 2006 3:18 PM
Mythran
Show quote Hide quote
"D. Patrick" <replywithinthegr***@thenotreal.com> wrote in message
news:PKkmg.3609$MF6.454@tornado.socal.rr.com...
>
> "Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message
> news:OD$ZiJXlGHA.3304@TK2MSFTNGP03.phx.gbl...
>>
>> "Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message
>> news:OwqUG6VlGHA.4268@TK2MSFTNGP05.phx.gbl...
>>>
>>> "D. Patrick" <replywithinthegr***@thenotreal.com> wrote in message
>>> news:R%dmg.3579$MF6.2782@tornado.socal.rr.com...
>>>> 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
>>>
>>
>> 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>
>
>

Possibly, test it and see :0

Mythran