1

I am running the latest version of Notepad++ 6.3.2 for Windows. Trying to do a "Find" using "Regular expression" without the "matches newline" checkbox checked on the following sample two lines text file.

hello
world

Search pattern hello.*world matches on nothing which is expected as "matches newline" is not checked (it is matched when checkbox is checked). However, pattern hello\s*world matches the two lines above which is a bit unexpected as "matches newlines" is NOT checked. I think an older version I used some time back didn't have that feature / bug. It is a bit annoying when I want to match on single lines only, with trailing white-space characters.

Is that expected?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
radikyl
  • 11
  • 1

2 Answers2

2

I try to explain it a bit:

the matches newlines should be (not 100% sure, didn't check the source code of notepad) the DOTALL flag of regex. which means, the dot . will match newline too.

what you had was \s, \s means Matches any whitespace character (spaces, tabs, line breaks). So it just works like that.

Kent
  • 189,393
  • 32
  • 233
  • 301
1

Looking at the interface it says ". matches newline"

In your second case of "hello\sworld" you are no longer using "." in the regex.

\s is meant to match \r or \n characters.

Perhaps a slight adaptation of Regex to match more than 2 white spaces but not new line would work for you

i.e. use "hello[ \t]*world" ?

Community
  • 1
  • 1
Adam Knights
  • 2,141
  • 1
  • 25
  • 48
  • Thanks Knightsy, I will stick to the adaptation "[ \t]*" as "\s*" matches the pattern on single line as well as on multiple lines i.e. "hello" on one line and "world" on next line. It seems "\s*" is overriding the unchecked "matches newline" checkbox. – radikyl Jul 24 '13 at 11:29
  • Its not overriding anything, the checkbox is the "dot matches newline" checkbox, so it only specifies the behavior of dot (".") in regex and has nothing to do with \s. - In any case, I'm glad my answer worked for you, please accept it if it has. – Adam Knights Jul 24 '13 at 12:29