Visual Studio中的多行正则表达式 [英] Multi-line regular expressions in Visual Studio

查看:187
本文介绍了Visual Studio中的多行正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以使Visual Studio在多行之间执行正则表达式替换(让匹配的行跨过边界)?我知道我可以使用许多编辑器,但是对于Visual Studio却没有此功能,这似乎很奇怪.我想念什么吗?

Is there any way to get Visual Studio to perform a regex replace across multiple lines (let the match cross line boundaries)? I know there are many editors I can use for this, but it seems strange that this feature has been left out of Visual Studio. Am I missing something?

推荐答案

使用文件替换对话框 Ctrl - Shift - H 和单行选项(?s):

Use the replace in files dialog Ctrl-Shift-H and the single line option (?s):

(?s)start.*end

发现

start
two
three
end

单行表示:每个文件都被视为单行,点.匹配换行\n.缺点:您必须使用全部查找并替换全部或手动替换.查找下一个不起作用.

Singleline means: each file is treated as single line, dot . matches newline \n. Downside: you must use Find All and replace all, or replace by hand. Find next does not work.

对于非模式对话框 Ctrl - H 并查找下一个,请使用(.*\n)*匹配任意行:

For the non-modal dialog Ctrl-H and find next, use (.*\n)* to match any number of lines:

start(.*\n)*.*end

无论哪种方式,您都可以通过插入\n用多行替换您的发现.

Either way, you can replace your findings with multiple lines by inserting \n.

这篇关于Visual Studio中的多行正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆