Menu

#3062 Regexps with lookbehind not working in xml mode files

closed
nobody
None
5
2012-03-27
2008-04-19
No

Regular expressions with positive and negative lookbehind aren't working with edit modes. Negative lookbehind matches everything, positive lookbehind matches nothing. This is very annoying, because some code cannot be highlighted correctly without these constructs.

Example string: "cab bed babe".
<SEQ_REGEXP TYPE="OPERATOR">(?&lt;!a)b</SEQ_REGEXP>
matches all b's although it should only match the 2nd and 3rd
<SEQ_REGEXP TYPE="OPERATOR">(?&lt;=a)b</SEQ_REGEXP>
matches no b's although it should match the 1st and 4th

Maybe it has something to do with the substitution '&lt;' for '<' ?

Discussion

  • Marcelo Vanzin

    Marcelo Vanzin - 2008-05-01

    Logged In: YES
    user_id=75113
    Originator: NO

    I think this is because of the way the TokenMarker class uses the regular expression. It parses input in the following way, using your example:

    matcher("cab bed babe").lookingAt() -> no match, mark as default
    matcher("ab bed babe").lookingAt() -> no match, mark as default
    matcher("b bed babe").lookingAt() -> match b, mark as OPERATOR
    matcher(" bed babe").lookingAt() -> no match, mark as default
    matcher("bed babe").lookingAt() -> match b, mark as OPERATOR
    matcher("ed babe").lookingAt() -> no match, mark as default

    (etc etc etc)

    So the way it "goes forward" in the string kinda breaks lookbehind. Maybe there's a way to not re-create the matcher every time, and instead use find() to provide the same functionality?

     
  • Alan Ezust

    Alan Ezust - 2011-12-04
    • assigned_to: nobody --> daleanson
     
  • Dale Anson

    Dale Anson - 2011-12-07
    • status: open --> pending
     
  • Dale Anson

    Dale Anson - 2011-12-07

    Is there a specific use case for this, that is, do you have a specific mode that does not highlight correctly? If so, please provide the details. Without specifics, this isn't a bug, but sort of a feature request for something that doesn't seem to be needed.

     
  • Dale Anson

    Dale Anson - 2012-03-27

    Closing, no activity for a long time, no follow up to say this is still needed.

     
  • Dale Anson

    Dale Anson - 2012-03-27
    • assigned_to: daleanson --> nobody
    • status: pending --> closed
     

Log in to post a comment.