AlwaysLearning
AlwaysLearning

Reputation: 8051

Single line regex search in Notepad++

When I use "Find Next" to find the next match for a regex in Notepad++ (v. 7.8.6), the match can span several lines. Is there a way to limit the matches to a single line, i.e. to search each line separately?

Upvotes: 1

Views: 2161

Answers (2)

sberezin
sberezin

Reputation: 3296

I achieved one-line-only behavior in Notepad++ regexp by using this approach:

^[^'\n]*loopdata.*$

I searched lines in a VBA script where 'loopdata' was before ' sign.
I started with [^'] and result included several lines.
So excluding also line breaks did the job: [^'\n].

Upvotes: 1

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627419

There is no option in Notepad++ to disable matching across multiple lines.

The match texts in the Find results window are truncated, that does not mean that Notepad++ can be "set" to search within single lines.

The ". matches newline" option only affects the . behavior: if the option is OFF, . does not match line break chars by default.

However, \s (any whitespace chars), \W (any non-word chars), [^57] (any char but 5 and 7) patterns still may "overflow" from line to line because line break chars are among those characters those patterns match.

Upvotes: 1

Related Questions