Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex weirdness



"Todd O'Bryan" <email@hidden> wrote:

>But the point is that it should only match > which are NOT preceded by the
>pattern.
>
>Why would an engine "match" a pattern it's not supposed to match?

How is an engine supposed to "not match" a pattern except by comparing to a
pattern and negating the outcome of matching?

If you haven't done so yet, please read about the limitations of
look-behind described in the section entitled "Important Notes About
Lookbehind":
<http://www.regular-expressions.info/lookaround.html>

This paragraph in particular seems to have some relevance:
The bad news is that you cannot use just any regex inside a lookbehind. The
reason is that regular expressions do not work backwards. The string must
be traversed from left to right. Therefore, the regular expression engine
needs to be able to figure out how many steps to step back before checking
the lookbehind.

This also seems to have some bearing:
.... These regex flavors recognize the fact that finite repetition can be
rewritten as an alternation of strings with different, but fixed lengths.
The only regex flavor that I know of that currently supports this is Sun's
regex package in the JDK 1.4.

Which also suggests an experiment. Specifically, see if you get different
behavior by using an actual "alternation of strings with different, but
fixed lengths." As in:
<br/|<br|<b/|<b

or this variation with ascending string-lengths:
<b|<b/|<br|<br/

As a last resort, you could look at the source for the pattern-matching
engine in 1.4. It's probably written entirely in Java. If you have
installed the Java Developer Tools, you will have "src.jar", so you can
find out exactly what's going on.

If you find a bug, file a bug-report with Sun.

-- GG
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.