• Login
Community
  • Login

Find and Replace blank spaces (char32) with Regular Expression seems to Lock up NP++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
2 Posts 2 Posters 31.8k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    Stephen Frick
    last edited by Aug 26, 2015, 5:03 PM

    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,

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by Aug 26, 2015, 6:25 PM

      Hello Stephen,

      In my opinion, Stephen, you didn’t understand, exactly, the use of the . matches new line option. 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.*789 with 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 :

      SEARCH = +, 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 :

      SEARCH = \x20\x20+ and REPLACE = \x20 ( decimal number 32 = hexadecimal number 20 )

      You could also use a look-behind to detect the first space :

      SEARCH = (?<= ) +, 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.

      Best Regards

      guy038

      P.S. :

      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.0 version, at the TWO addresses below :

      http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

      http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

      • 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

      1 Reply Last reply Reply Quote 0
      2 out of 2
      • First post
        2/2
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors