in reply to Double regex match not working correctly.

Note that you can avoid doing the second regex all together by putting the two arrays together, the longer phrases in front of the shorter ones to allow the greediness of regex to work..

That is, if you make the join in join "|", (@array, @array2), then I get the following without modifying your regex at all:

string after first - there is a <B>foo bar</B> and a <B>bar foo</B> an +d also <B>foo</B> and <B>bar</B>.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Double regex match not working correctly.
by the_0ne (Pilgrim) on May 24, 2001 at 19:37 UTC
    Thanks Masem and all.

    I thought of doing it that way first, but in my mind I didn't think it would work because I thought something like this would happen...

    string after first - <B>bar</B> there is a <B><B>foo</B> <B>bar</B></B +> and a <B><B>bar</B> <B>foo</B></B> and also <B>foo</B> and <B>bar</ +B>.
    See how the multiple words also matches for the single words and now we have compounded <B> tags. That's what I thought would have happened. Since I was using the g modifier I would think the regex would go through and transform the multiple word matches and then go through and match the single words also, which would not be good. But now I see that it would have worked. Next time I'll try my first instinct.

    Thanks to all that posted.