How to search for strings that include newlines in Notepad++

0

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

user1021085

Posted 2018-02-15T19:07:44.043

Reputation: 129

Answers

3

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 a

It 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.

LPChip

Posted 2018-02-15T19:07:44.043

Reputation: 42 190

I want to search different quotes and won't be sure where they did their lines breaks. Is there a way to just say "search this string, match even if it's broken up by new lines" or something? – user1021085 – 2018-02-15T19:23:20.590

1For that you will need RegEx, and check the option at the right to search past linebreaks. – LPChip – 2018-02-15T19:24:20.137

I'm sorry how would that look like? – user1021085 – 2018-02-15T19:28:35.757

I'm starting to think you are trying to do something with the wrong kind of tools or using the wrong method here. What is it exactly that you want to achieve in the end? – LPChip – 2018-02-15T19:33:48.707

I want to be able to search through the subtitle files and find quotes (episode, context, etc) – user1021085 – 2018-02-15T19:35:25.910

Then I would suggest to search/replace the entire file and remove all \r\n on lines. That would effectively merge all sentences to one sentence. You can then search freely. – LPChip – 2018-02-15T19:41:49.207

0

Notepad uses PCRE (Perl Compatible Regular Expression) for Search/Replace. So you can use \s for white space, e.g. with one space/newline

looking\sfor

or this regular expression with at least one or many spaces/newlines

looking\s+for

See 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.

Olaf Dietsche

Posted 2018-02-15T19:07:44.043

Reputation: 421

0

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!

Kyle H

Posted 2018-02-15T19:07:44.043

Reputation: 338