Menu

#2489 positive lookahead does only work in the end

minor bug
closed-works-for-me
nobody
5
2017-12-02
2005-12-05
velniava
No

the positive look ahead expression (?= ) seems to be
working only in the end of the expression. For ex. if
an expression for some words inside tags is needed we
expect this to do the work:
(?= <([^>]*))thewordIsearch(?=([^<]*)>)

it doesn't work, but of course if I remove look
ahead: "(<([^>]*))thewordIsearch(?=([^<]*)>)" it
works, but it doesnt hide the text before the word I
search for.

Discussion

  • Robert Schwenn

    Robert Schwenn - 2007-02-14

    Logged In: YES
    user_id=1486645
    Originator: NO

    Sill valid for jEdit 4.3pre9.

    SUN JRE 1.5.0_11
    WinXP SP2

     
  • Eric Le Lay

    Eric Le Lay - 2010-03-27

    I'm by no mean a regexp expert (far from it), but shouldn't one use a positive look-behind ?
    At first, I tried (?<=<([^>]*))bonjour(?=([^<]*)>)
    but got a
    java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum
    length near index 11 (?<=<([^>]*))bonjour(?=([^<]*)>)
    So I added an explicit bound and found that (?<=<([^>]{0,100}?))bonjour(?=([^<]*)>) works

     
  • Eric Le Lay

    Eric Le Lay - 2010-03-27
    • status: open --> pending-invalid
     
  • Eric Le Lay

    Eric Le Lay - 2010-03-27

    my suggestion doesn't work on inputs like this : "<lebonjour>" while it should !
    It's a bug in the regex engine,
    see : http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6284152

     
  • Eric Le Lay

    Eric Le Lay - 2010-03-27
    • status: pending-invalid --> open
     
  • Eric Le Lay

    Eric Le Lay - 2010-03-27

    the workaround suggested in the sun bug report works : "bonjour(?<=<([^>]{0,100}bonjour))(?=([^<]*)>)".

    Attached is a beanshell to demonstrate the problem with java.util.regex : open it and run it.
    The second alternative works, but the first one doesn't.

     
  • Eric Le Lay

    Eric Le Lay - 2010-03-27

    beanshell to run on itself

     
  • Roman Tsourick

    Roman Tsourick - 2017-12-02
    • status: open --> closed-works-for-me
     
  • Roman Tsourick

    Roman Tsourick - 2017-12-02
    1. Lookahead can not stand before the subject.
    2. Sun fixed the bug.
    3. The beanshell script works, both patterns.

    Closing...

     

Log in to post a comment.