Menu

#135 negative lookahed won't work

Invalid
nobody
None
Medium
Defect
2010-06-11
2010-06-01
Anonymous
No

Originally created by: matteo.t... (code.google.com)@gmail.com

What steps will reproduce the problem?
1. try a regex with a negative lookahed on a text file, for example
"javascript:\s*(?!history)" is the one I was using

What is the expected output? What do you see instead?
I expected to see only the string "javascript:" NOT followed by the word
"history", instead those were returned too.

What version of the product are you using? On what operating system?
version 1.4.2 on windows7 32 bit

Discussion

  • Anonymous

    Anonymous - 2010-06-03

    Originally posted by: tortoisesvn

    Works just fine for me.

    Using a file with two lines:
    javascript:history
    javascript:test

    and the regex 'javascript:\s*(?!history)'
    I get one match on line two, and not two matches.

    Status: NeedsInfo

     
  • Anonymous

    Anonymous - 2010-06-03

    Originally posted by: matteo.t... (code.google.com)@gmail.com

    mine had lines like "javascript: history.go(-1);" but they would be reported too...
    I'll do another test, perhaps I've made some mistake.

     
  • Anonymous

    Anonymous - 2010-06-11

    Originally posted by: matteo.t... (code.google.com)@gmail.com

    Ok, here is what I've discovered: some of my files contained pieces like
    href="javascript: history.go(-1)"
    which I need to keep, while there are other parts like
    onlick="javascript: [...]"
    where I want to cut out the "javascript: " part.

    Please notice the space after the colon.

    it seems that if I use the regex "javascript:\s*(?!history)" I get also the strings I want to preserve, while if I use the regex "javascript:\s+(?!history)" I get the correct result, though I do not understand why this happens. Is it a "bug" or a problem with me not understanding regex?

     
  • Anonymous

    Anonymous - 2010-06-11

    Originally posted by: tortoisesvn

    The negative lookahead has priority, so even though the '*' is greedy, it won't match until the lookahead is triggered.
    Use 'atomic grouping' to group the first part together:

    (?>javascript:\s*)(?!history)

    Status: Invalid

     
  • Anonymous

    Anonymous - 2010-06-11

    Originally posted by: matteo.t... (code.google.com)@gmail.com

    I see. Well then, sorry for having opened an issue that was not related to your program.

     
MongoDB Logo MongoDB