negative lookahed won't work
A powerful and fast search tool using regular expressions
Brought to you by:
steveking
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
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
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
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
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.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
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?
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
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
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
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.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: tortoisesvn
no problem :)