Visual Studio 中的正则表达式 Find &替换 - 搜索词之间有多个空格
我需要 Visual Studio 搜索和替换功能的正则表达式,如下所示:
搜索以下术语:sectorkey in (
上述每个项之间可能有多个空格3 个搜索词,甚至多个换行符/回车符
搜索词正在查找 SQL in 语句中具有硬编码 SectorKey 值的 SQL 语句,这些语句需要用 SQL 连接替换。声明 - 这将手动完成。
I require a regular expression for the Visual Studio Search and Replace functionality, as follows:
Search for the following term: sectorkey in (
There could be multiple spaces between each of the above 3 search terms, or even multiple line breaks/carriage returns.
The search term is looking for SQL statements that have hard-coded SectorKey values inside a SQL in statement. These need to be replaced with a SQL join statement - this will be done manually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“查找内容”框右侧的小箭头是您的朋友,可以帮助您解决 MS 正则表达式语法的变幻莫测。
换行符由
\n
表示,因此您只需执行sectorkey( |\n)+in( |\n)+\(
(您需要转义左括号)在您的搜索表达式中,因为它用于分组。)The little arrow to the right of the Find What box is your friend and can help you with the vagaries of the MS regex syntax.
Newline is represented by
\n
, so you can just dosectorkey( |\n)+in( |\n)+\(
(You need to escape the open paren in your search expression, since that's used in grouping.)我相信
:Wh+
就是你想要的。 Visual Studio 正则表达式的风格很奇怪;如果您查阅,您往往会获得更好的结果官方参考。当涉及到 VS 时,“主流”正则表达式的专业知识往往是一种障碍而不是帮助。I believe
:Wh+
is what you want. The Visual Studio regex flavor is very strange; you'll tend to get better results if you consult the official reference. Expertise with "mainstream" regexes tends to be more of a handicap than a help when it comes to VS.您可以使用
\s+
搜索一个或多个相邻的空白字符(包括制表符、CR、LF 等),因此您的正则表达式可能最终看起来类似于sectorkey\s+in\ s+\(
。编辑...
正如 Joe 在评论中指出的那样,Visual Studio 似乎不支持查找/替换表达式中的
\s
,在这种情况下,您可能需要使用类似[\n:b]
的内容,然后正则表达式将变为sectorkey[\n:b]+in[\n:b]。 ]+\(
.You can use
\s+
to search for one or more adjacent whitespace characters (including tab, CR, LF etc), so your regex would presumably end up looking something likesectorkey\s+in\s+\(
.Edit...
As Joe points out in his comment, it seems that Visual Studio doesn't support
\s
in Find/Replace expressions, in which case you'll probably need to use something like[\n:b]
instead. The regex would then becomesectorkey[\n:b]+in[\n:b]+\(
.