VS2015 或 NP++ 中的多行正则表达式
Multiline regex in VS2015 or NP++
我需要在多个文件中替换以下模式。
this\.dialogs = {.*};
当我在此处设置 single line
标志时,效果很好:
https://regex101.com/r/dF2yG3/2
但是我不能让它在像 VS 或 Notepad++ 这样的编辑器中工作,它只会匹配一行。
如何在这些编辑器中更改正则表达式或设置标志,以便使其跨越多行?
请注意,您只想使用
(?s)this\.dialogs = \{.*\};
如果你想匹配从 this.dialogs = {
到 last }
.
的字符串
要仅匹配最接近的 };
,请使用
(?s)this\.dialogs = \{.*?\};
(?s)
内联修饰符强制点匹配任何字符包括 换行符。
在Notepad++中,你可以使用.
在Notepad++中匹配换行符查找和替换对话框中的选项,而不是(?s)
。
在Visual Studio 2015中(在VS2012、VS2013中也是),需要使用
this\.dialogs = {[\s\S\r]*?};
匹配从 this.dialogs = {
到最接近的 };
的字符串
转义括号并激活 . matches newline
在记事本中:
this\.dialogs = \{.*\};
还是更好用
this\.dialogs = \{[^}]*\};
我需要在多个文件中替换以下模式。
this\.dialogs = {.*};
当我在此处设置 single line
标志时,效果很好:
https://regex101.com/r/dF2yG3/2
但是我不能让它在像 VS 或 Notepad++ 这样的编辑器中工作,它只会匹配一行。
如何在这些编辑器中更改正则表达式或设置标志,以便使其跨越多行?
请注意,您只想使用
(?s)this\.dialogs = \{.*\};
如果你想匹配从 this.dialogs = {
到 last }
.
要仅匹配最接近的 };
,请使用
(?s)this\.dialogs = \{.*?\};
(?s)
内联修饰符强制点匹配任何字符包括 换行符。
在Notepad++中,你可以使用.
在Notepad++中匹配换行符查找和替换对话框中的选项,而不是(?s)
。
在Visual Studio 2015中(在VS2012、VS2013中也是),需要使用
this\.dialogs = {[\s\S\r]*?};
匹配从 this.dialogs = {
到最接近的 };
转义括号并激活 . matches newline
在记事本中:
this\.dialogs = \{.*\};
还是更好用
this\.dialogs = \{[^}]*\};