How to search for strings that include newlines in Notepad++
I'm going through subtitle files so there are stuff like
442
00:24:18,017 --> 00:24:20,551
Now you're just looking
for a scapegoat.
and I'm wondering how I can search for "just looking for a" and have it find that. Right now "you're just looking" gets a match, "for a scapegoat" gets a match, "looking for" does not get a match.
I've tried putting the search mode to normal/extended
3 Answers
If you use Extended search, you can search for \r\n as a newline when your document was created on windows. When it was created on linux, it is most likely only \n
So if you search for:
just looking\r\nfor aIt should find you the matches. To make exactly sure what to search for, press the ¶ button in the toolbar to enable showing all special chars.
Any CR is found searching for \r and any LF is found searching for \n.
Look closely for any spaces at the beginning and end of the line and search for those too.
6Notepad uses PCRE (Perl Compatible Regular Expression) for Search/Replace.
So you can use \s for white space, e.g. with one space/newline
looking\sforor this regular expression with at least one or many spaces/newlines
looking\s+forSee also regular-expressions.info - Shorthand Character Classes
\s stands for "whitespace character". Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a line break, or a form feed. Most flavors also include the vertical tab, with Perl (prior to version 5.18) and PCRE (prior to version 8.34) being notable exceptions. In flavors that support Unicode, \s normally includes all characters from the Unicode "separator" category. Java and PCRE are exceptions once again. But JavaScript does match all Unicode whitespace with \s.
There are multiple ways, hooray for regexes and Perl!!!
1. Try putting it in regular expression made and search for "just looking.*?for a" without the quotes and make sure the checkbox is checked that will make the . character match newlines. this matches the newline, put []* around .*? if you don't want it to match newline also.
2. Literally match the \r\n as in the other answer. Put into regex made and search for "just looking\r\nfor a" this matches the newline, put []* around \r\n if you don't want it to match newline. Add \s+ inside the [] brackets to match spaces too.Hope this helps! Please comment for clarification!