This time, it easy to see that the parts of text :Īfter a STOP boundary and before a START boundaryĪre not modified at all by the replacement, as expected ! Thus, the string OP and further stuff should not be modified and the new match would necessarily catch an other string START, so the beginning of an other allowed region ! As this new match do not start where the previous match ends, the \G assertion forces the failure of the match attempt ! However, due to the look-ahead (?!OP), it must advance of one position in order that the condition (?!OP) is true. Now, the regex engine is located right before the OP string of the word STOP. I had the idea to only search for the beginning of the STOP string, for instance the string ST and add a negative look-behind (?!OP), executed once only, after the START string or location of the previous matchįirst, extra chars before STOP as well as ST are changed as the string \r\nST
#Notepad++ regex except how to
Indeed, after matching some stuff ending with STOP, the search process restarts immediately and considers the following characters as we have specified the (?s) modifier ! So, how to tell the regex engine, to directly jump to the next START boundary ? Unfortunately, it seems that the 0 digits are also processed like the other numbers, although they are not part of a START (B) REPLACE (?1\1\r\n\r\n)(?2\2(?3:\r\n))(?4\r\n\4)Īnd we will take the opportunity to add a line-break, right before the closing section STOP No problem, we may modify this S/R to include the search of STOP, too, within a non-capturing group, giving : (B) SEARCH (?sx-i)(?: (START) | (?!\A)\G ) (?: (?!STOP). However, between the last number and the closing boundary STOP, some extra characters are still not deleted :-( The different numbers, located between START and STOP are correctly rewritten one per line and extra stuff is deleted If, in addition, we want to add a line-break, after the START opening section, we need, from the generic regex, discussed before by to slightly modify this regex, as we search for two independent strings, simultaneously. START-12345-6789-1111199999-DEF-STOPĪnd let’s suppose that we want to rewrite all numbers, between the boundaries START and STOP, each on a new line If you wanted to stick closer to Notepad++, you could use one of the scripting plugins like PythonScript to access the file currently open in Notepad++ with your script, but implement the start and end checks similar to what did, but in Python and using the PythonScript interface to access the contents of the document open in Notepad++.īefore giving, in the second part of this post, the specific solution for here is a simple example to show you the difficulties I had to face ! has provided an off-topic powershell answer. Maybe will be able to find time to experiment with this one.Īlternately, it would be pretty easy in some tool other than pure Notepad++. My next guess is that the generic would have to be modified somewhat, probably adding an or-condition next to the ESR… but I’m not sure how. My initial guess was that the FR was going to be something like ((?!).)+… unfortunately, that exact sequence won’t work because when it advances one step beyond the < of the