开发者

Why doesn't this regular expression work in Notepad++?

EDIT: It was some issue with Notepad++'s regex engine. The regex worked fine in Py开发者_开发问答thon.

I'm working in Notepad++. I tried to make a regexp that would transform this (if you're curious, it's a Spanish guide for a game):

*Acero: En la Estatua de Gabomba

**Absorbe PV de un enemigo

To this:

====Acero====

*En la Estatua de Gabomba

*Absorbe PV de un enemigo

I came up with this, but it doesn't match the text:

\*([^:]+): ([\w ]+)\n\*\*([^\n]+)

Am I missing something obvious?


It seems that Notepad++ cannot find line breaks in regex mode. You'll have to replace the line breaks with, say, |, in extended mode, apply the regex on your new string, then replace the |s with line breaks.


Your regex is correct. Try to search for \*([^:]+): ([\w ]+) and \*\*([^\n]+) separately and it will match.

It is just that Notepad++ does not support multiline regular expressions (because Scintilla doesn't). Note that there are two different search dialogs available: Ctrl+F shows the builtin dialog, Ctrl+R shows TextFX's dialog which has more options. But TextFX doesn't support multiline search either.


As another option to the above 2 answers, TextPad supports POSIX regular expression syntax (including multiline).

To set TextPad to use POSIX: Configure -> Preferences -> Editor -> "Use POSIX regular expression syntax"

I prefer Notepad++ myself after using TextPad for many years, but always keep TextPad on my system for multiline regular expressions and a few other things it does well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜