使用正则表达式搜索和替换包括lookbehinds在VS2017中不起作用

问题描述 投票:2回答:1

在Visual Studio 2017中,我试图改变这样的一些行:

[AddressId] [int] NOT NULL,
[CountryId] [int] NULL,
[POBoxCountryId] [int] NULL,
[Name] [nvarchar] (100) NULL,

进入这个:

[AddressId] int NOT NULL,
[CountryId] int NULL,
[POBoxCountryId] int NULL,
[Name] nvarchar (100) NULL,

在我看来,正则表达式:(?<=\[\w+\]\s)\[(\w+)\]应该与第二对括号完全匹配,并捕捉内部的内容。

当我在RegexStorm中检查它时,情况似乎就是这种情况:regexstorm link

此外,在Visual Studio中,我可以看到,如果我进行查找,也可以正确找到它。显示匹配的行。


但是,如果我尝试进行查找和替换(由$1替换),则不会进行替换。 (替换工作在regexStorm)

我究竟做错了什么 ?

.net regex visual-studio-2017 lookbehind find-replace
1个回答
3
投票

你可以用

找到什么:(\[\w+]\s+)\[(\w+)] 替换为:$1$2

regex demo

细节

  • (\[\w+]\s+) - 第1组($1):[,1 +字形字符,]和1+空格
  • qazxsw poi - 一张qazxsw poi图表
  • \[ - 第2组([):1+个字符
  • qazxsw poi - 一张qazxsw poi图表。
© www.soinside.com 2019 - 2024. All rights reserved.