regex 在Visual Studio中使用通配符/正则表达式进行查找和替换

thtygnil  于 2023-03-04  发布在  其他
关注(0)|答案(3)|浏览(321)

我需要将receiveTimeOut属性的不同值替换为receiveTimeOut="59:59:59"在Visual Studio中,可以使用通配符搜索来完成此任务吗?

<endpoint receiveTimeOut="10:10:20" someOtherProperty="x1" yetAnotherProperty="y1" />
<endpoint receiveTimeOut="10:50:20" someOtherProperty="x2" yetAnotherProperty="y2" />
...
<endpoint receiveTimeOut="30:50:20" someOtherProperty="x3" yetAnotherProperty="y3" />

**我尝试:**在“查找和替换”对话框中使用通配符选项receiveTimeOut="*",但这会选择整行receiveTimeOut="10:10:20" someOtherProperty="x1" yetAnotherProperty="y1" />

正如你可能已经猜到的,我正在编辑WCF服务web.config,并且不得不手动&重复地执行这个任务。

zkure5ic

zkure5ic1#

正在使用regex选项...
查找:<endpoint receiveTimeOut="[^"]+"
然后...
更换:<endpoint receiveTimeOut="59:59:59"
[^"]+部分使用一个否定字符类,它匹配除双引号外的任何字符。+将匹配它一次或多次。

3duebb1j

3duebb1j2#

事实证明,这对于正则表达式来说实际上非常简单。
只需使用.*作为通配符并选中Use regular expressions
例如,我有一些网格,我想查找属性为Visible="False"的列,因此字符串可能为:

telerik:GridBoundColumn name="name" Visible="False"

我的搜索字符串将是:"GridBoundColumn.*Visible="False""
好的。

guykilcj

guykilcj3#

Ahmad的方法是可行的,但作为一个天真的、有点不同的选择,你可以搜索:

receiveTimeOut="[0-9]*\:[0-9]*\:[0-9]*"

这要求receiveTimeOut值的双引号之间的数据有两个冒号(转义),冒号周围有任意位数。

相关问题