Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline Regular Expression search and replace!

I've hit a wall. Does anybody know a good text editor that has search and replace like Notepad++ but can also do multi-line regex search and replace? Basically, I am trying to find something that can match a regex like:

search oldlog\(.*\n\s+([\r\n.]*)\);
replace newlog\(\1\)

Any ideas?

like image 410
Scott Avatar asked Sep 17 '09 20:09

Scott


People also ask

What is multiline in regex?

Multiline option, or the m inline option, enables the regular expression engine to handle an input string that consists of multiple lines. It changes the interpretation of the ^ and $ language elements so that they match the beginning and end of a line, instead of the beginning and end of the input string.

Can you use regex in Find and Replace?

When you want to search and replace specific patterns of text, use regular expressions. They can help you in pattern matching, parsing, filtering of results, and so on. Once you learn the regex syntax, you can use it for almost any language. Press Ctrl+R to open the search and replace pane.

How do I find and replace multiple lines in Visual Studio?

CHANGE: The default keyboard shortcut for “Multiline Find/Replace” was Ctrl+Alt+F but it was not applied because this shortcut was already taken by “F# Interactive”. So, the new default shortcut is Ctrl+M, Ctrl+F.

How do you find and replace multiple lines in Notepad ++?

It's easy to do multiline replace in Notepad++. You have to use \n to represent the newline in your string, and it works for both search and replace strings. You have to make sure to select "Extended" search mode in the bottom left corner of the search window. This is in a file already open.


1 Answers

Notepad++ can now handle multi line regular expressions (just update to the latest version - feature was introduced around March '12).

I needed to remove all onmouseout and onmouseover statements from an HTML document and I needed to create a non-greedy multi line match.

onmouseover=.?\s*".*?"

Make sure you check the:

[ ] . matches newline
checkbox if you want to use the multi line match capability.
like image 185
Mark Salisbury Avatar answered Sep 21 '22 13:09

Mark Salisbury