Multiline Regular Expression search and replace!

2019-01-18 08:34发布

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?

14条回答
淡お忘
2楼-- · 2019-01-18 09:18

TextPad has good Regex search and replace capabilities; I've used it for a while and am pretty happy with it.

TextPad screenshot http://i31.tinypic.com/2bb22q.png

From the Features:

Powerful search/replace engine using UNIX-style regular expressions, with the power of editor macros. Sets of files in a directory tree can be searched, and text can be replaced in all open documents at once.

For more options than you could possibly need, check out "Notepad++ Alternatives" at AlternativeTo.net.

查看更多
疯言疯语
3楼-- · 2019-01-18 09:19

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.

查看更多
Deceive 欺骗
4楼-- · 2019-01-18 09:21

you can use Python Script plugin for Multiline Regular Expression search and replace! - http://npppythonscript.sourceforge.net/docs/latest/scintilla.html?highlight=pymlreplace#Editor.pymlreplace

# This example replaces any <br/> that is followed by another on the next line (with optional spaces in between), with a single one
editor.pymlreplace(r"<br/>\s*\r\n\s*<br/>", "<br/>\r\n")
查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-18 09:24

EditPad Pro has better regex capabilities than any other editor I've ever used.

Also, I suspect you have an error in your regex — [\r\n.] will match only carriage returns, newlines, and full stops. If you're trying to match any character (i.e. "dot operator plus CR and LF), try [\s\S] instead.

查看更多
We Are One
6楼-- · 2019-01-18 09:26

I use Notepad++ all the time but it's Regex has alway been a bit lacking.

Sublime Text is what you want.

查看更多
放荡不羁爱自由
7楼-- · 2019-01-18 09:26

The latest version of UltraEdit has multiline find and replace w/ regex support.

Or if you're OK with using a more specialized regular expression tool for this, there's Regex Hero. It has the side benefit of being able to do everything on the fly. In other words, you don't have to click a button to test your regular expression because it's automatically tested after every keypress.

Personally, I'd use UltraEdit if I'm looking to replace text in multiple files. That way I can just select the files to replace as a batch and click Replace. But if I'm working with a single text file and I'm in need of writing a more complex regular expression then I'd paste it into Regex Hero and work with it there. That's because Regex Hero can save time when you see everything happen in real-time.

查看更多
登录 后发表回答