On 2/27/02 9:00 PM, "Jerry Hamlet" <jerry at hamletzone dot com> wrote:
> When you have a greedy pattern before what you want to match is that the
> RegEx has to backtrack from the point that it finds the ">" character to
> fulfill the rest of the pattern. This happens all the way back to the
> opening "<" where it eventually decides that it can't fulfill the pattern.
>
> It helps sometimes to translate your regex patterns into plain english. I.e,
> for your example it would go something like this: "Find a left-angle bracket
> character. Then grab all characters that are not a right-angle bracket. Ok,
> now back up till you find either 'src', 'href' or 'background'..." at this
> point what the RegEx is doing is stepping back a character at a time trying
> to fulfill that request, and it will try every character up to the opening
> angle bracket.
>
> Jeff Friedl explains it a lot better than I.
Hrm. Interesting. Maybe breaking it up would be better. But RegEx is
generally pretty fast, so I think that unless speed is really an issue, mine
would work ok. I didn't actually read the 2-part one to see if I thought it
would work correctly (was it tested?), but if it does, that might be faster.
I don't know.
--
Kevin Ballard
kevin at sb dot org
Email from Korea or China must go to <kevin dot nb at sb dot org>
http://kevin.sb.org/
|