Find and Replace blank spaces (char32) with Regular Expression seems to Lock up NP++
Stephen Frick last edited by
I have a large text document that I’m removing multiple blanks (char32) and replacing them with a single space - I’m using the Replace - Find what: ( )* and Replace with is a single space. I’m using Regular expression and the . matches newline is checked. When I run this on my text, no matter the size it locks up and shows (Not Responding) on the window. It seems like an infinite loop. I don’t want to use \s* because I want various control characters, all I want is char32 to be found and replaced.
Am I doing something wrong or is this a bug?
Thanks for your help,
guy038 last edited by
In my opinion, Stephen, you didn’t understand, exactly, the use of the
. matches new lineoption. By default, with the regex engine of N++, the special character dot
.matches ANY character DIFFERENT from the 3 characters, below :
The New Line character, displayed as LF, =
\n( \x0a )
The Carriage Return character, displayed as CR, =
\r( \x0d )
The Form Feed character, displayed as FF, =
\f( \x0c )
So, when you CHECK the option . matches new line, then the dot matches, absolutely, ALL the characters of a file. This option allows the user to build multi-lines searches.
For instance, the regex
123.*789with the .matches new line set, tries to match the longest string, from a first occurrence of 123 to the last occurrence of 789, in the current file, even though the string 789 is located some lines after the string 123 :-)
So, as you can see, this option has no relation, at all, with the search of spaces, anyway !
To achieve your S/R ( Multiple spaces -> ONE space ), that’s quite easy :
+, with TWO spaces before the + sign and REPLACE = ONE space
The search regex matches a single space, followed by a non null sequence of spaces. An other syntax would be :
\x20\x20+and REPLACE =
\x20( decimal number 32 = hexadecimal number 20 )
You could also use a look-behind to detect the first space :
(?<= ) +, with a space after the = sign and before the + sign and REPLACE = Nothing.
However, due to a bug of the regex engine, you must click on the Replace All button, ONLY. Don’t use the Replace button, for the S/R, just above.
You’ll find good documentation, about the new Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v1.48.0 ), used by
Notepad++, since its
6.0version, at the TWO addresses below :
The FIRST link explains the syntax, of regular expressions, in the SEARCH part
The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part