Negative lookbehind regular expression not working on Notepad++
-
@PeterJones The wonderful thing about the (*SKIP)(*F) method is that it can be used for negative look aheads also like this:-
(MAIN Regex Search)(String1|String2)(*SKIP)(*F)|(MAIN Regex Search) | <------------- What I want to SKIP ------------><-What I want to MATCH->
-
@dr-ramaanand said in Negative lookbehind regular expression not working on Notepad++:
The wonderful thing about the (*SKIP)(*F) method is that it can be used for negative look aheads also like this
But pointless, because lookaheads (negative or positive) can have variable width, so if you want a lookahead, just use a lookahead.
-
@PeterJones The (*SKIP)(*F) method can be of variable width but it can be used only for negative look aheads and negative look behinds
-
Peter’s last point (which you missed) was that lookaheads are best done with native regex syntax, because it is more obvious that way.
And he probably would have confused you less if he had left out
(negative or positive)
from his sentence; doing that doesn’t change the meaning. -
Hello, @peterjones and All,
OK. I going to prepare a blog post regarding the
(*SKIP)(*F)
feature !However, be patient because I’ll try, first :
-
To find out some other pertinent examples from various regex sites
-
To propose alternatives to the
(*SKIP)(*F)
syntax when it’s possible !
BR
guy038
-
-
@guy038 please create the blog to show how to use the
(*SKIP)(*FAIL)
regular expression, not an alternative to it. @PeterJones may be able to create an alternative to it. If @PeterJones wants to still use his method for what I have typed as my block for testing, he can do it in 2 parts; first using the regular expression,(<span\b[^>]*?color\s*:\s*black[^>]*>\s*|<p\b[^>]*?color\s*:\s*black[^>]*>\s*<span\b[^>]*>\s*)\K(<code\s*style="background-color:\s*transparent;">)
in the find field and a unique string (say for example, a unique name like, “Czeslawski”) in the replace field, he can replace the<code\s*style="background-color:\s*transparent;">
with that unique string. Then he can do what is needed to the other strings of<code\s*style="background-color:\s*transparent;">
and then again replace the unique string (“Czeslawski” in this case) with<code\s*style="background-color:\s*transparent;">
. If it is something simple, this example should be sufficient: https://stackoverflow.com/questions/17286667/regular-expression-using-negative-lookbehind-not-working-in-notepad -
Hello, @dr-ramaanand,
When I said :
To propose alternatives to the
(*SKIP)(*F)
syntax when it’s possible !I’m not talking about a work-around, using a several-steps regex, but, indeed, other direct regexes, without the
(*SKIP)(*F)
syntax, which are, sometimes, even shorter !You’ll understand what I mean., sooner !
Best Regards,
guy038
-
@guy038 I will understand it only after you post that regular expression (RegEx) here
-
This post is deleted! -
Hello, @peterjones and All,
Peter, Done ! Refer to :
I also added a link to this post in your
FAQ: Generic Regular Expression (regex) Formulas
post.Best Regards,
guy038
-
@guy038 So, if you have an alternative method to the
(*SKIP)(*FAIL)
method for the block posted right at the top of this thread for testing to match the same string you posted in post#16 above, please post it here -
@guy038 you can use the idea mentioned at www.drregex.com/2019/02/variable-length-lookbehinds-actually.html?m=1 if you please, for the above RegEx. @PeterJones can include that formula in the Notepad++ manual also, if he pleases.
-
@dr-ramaanand said:
www.drregex.com/2019/02/variable-length-lookbehinds-actually.html?m=1
Doesn’t appear to be a valid link, in fact, it seems to point back to the N++ Community site??
THIS is probably the correct link.
-
@guy038 The answer by User Doqnach mentioned at https://stackoverflow.com/questions/25563891/variable-length-look-behind can be used as an example.
-
@dr-ramaanand said:
The answer by User Doqnach mentioned at … can be used as an example.
Well, trying that (
/(?=(?=(?'a'[\s\S]*))(?'b'eat_(?:apple|pear|orange)_(?=\k'a'\z)|(?<=(?=x^|(?&b))[\s\S])))today|yesterday
) in Notepad++ yields:This is an error message I don’t think I’ve seen before.
Note that I tried it on a smallish file where nothing would have matched.
-
@Alan-Kilborn That RegEx should be
(?=(?=(?'a'[\s\S]*))(?'b'eat_(?:apple|pear|orange)_(?=\k'a'\z)|(?<=(?=x^|(?&b))[\s\S])))today|yesterday
- I corrected it on stackoverflow but my edit is awaiting moderation (others can see it with my corrections only after my edit gets approved). For your information, those are positive look behinds with a capture group named ‘a’ and a capture group named ‘b’ and need to be changed to negative look behinds. I am unable to skip anything with this or this. I want the result to be like in post#16