regex, lookbehind error
-
I tried (?<=\s+) for searching 2 or more empty (allowing tab or spacebar inserted) line but this gives me an error.
The error message is ‘Find : invalid regular expression’.I tested lookbehind and \s+ separately and both work fine. I want to know what is wrong when those two expressions are combined together.
Actually, even (?<=\s) work fine too, but when I add + or * to the right side of \s to allow multiple whitespaces, the error occurs. Someone help me please.
-
Lookbehinds must be of a fixed length. \s+ is not fixed width.
https://npp-user-manual.org/docs/searching/#assertions
edit: the manual also suggests a workaround using
\K, so instead of(?<=\s+)REALTEXT, use\s+\KREALTEXT -
Additionally to what @PeterJones said, I want to mention that this is a restriction of the boost regular expression engine that Notepad++ uses under the hood. There are a few regular expression engines that don’t have this restriction (see section Important Notes About Lookbehind >> at this site <<), but in Notepad++ we have to live with it.
-
@PeterJones Thank you so much, I understood what I need.
-
@dinkumoil Thank you, actually I’m studying regex with 'Mastering Regex by Jeffrey Friedl and maybe I didn’t consider the differences on those engines.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login