是否可以使用Regex/replace从替换框中的匹配框使用您的匹配?

是否可以使用Regex/replace从替换框中的匹配框使用您的匹配?,regex,replace,Regex,Replace,我有一长串这样的清单 sb.AppendLine(product.product_id.Length.ToString()) sb.AppendLine("product.product_id " + product.product_id.Length.ToString()) 我想使用regex search和replace将每一行都改成这样 sb.AppendLine(product.product_id.Length.ToString()) sb.AppendLine("product

我有一长串这样的清单

sb.AppendLine(product.product_id.Length.ToString())
sb.AppendLine("product.product_id " + product.product_id.Length.ToString())
我想使用regex search和replace将每一行都改成这样

sb.AppendLine(product.product_id.Length.ToString())
sb.AppendLine("product.product_id " + product.product_id.Length.ToString())
这是否可以通过正则表达式搜索和替换实现

我应该在搜索框中输入什么,在替换框中输入什么

是否可以从替换框中的匹配框中使用您的匹配项?是的,可以使用

我假设产品id是可变的。
搜索:

替换:

sb.AppendLine("product.$1 " + product.$1.Length.ToString())
是的,这是可能的,使用

我假设产品id是可变的。
搜索:

替换:

sb.AppendLine("product.$1 " + product.$1.Length.ToString())
在vb.net中

作为字符串的Dim str str=“sb.AppendLine(product.product\u id.Length.ToString())”

Dim RegexObj作为Regex RegexObj=New Regex(“^sb.AppendLine((.*.Length.ToString())$”)

作为字符串的Dim res res=RegexObj.Replace(str,“sb.AppendLine(“$1”“+product.product\u id.Length.ToString()))

在c#net中

字符串str=null; str=“sb.AppendLine(product.product\u id.Length.ToString())”

Regex RegexObj=默认值(Regex); RegexObj=newregex(“^sb\.AppendLine\(.*)\.Length\.ToString\(\)\)$”

字符串res=null; res=RegexObj.Replace(str,“sb.AppendLine(\“$1\”+product.product\u id.Length.ToString())”

vb.net中的

作为字符串的Dim str str=“sb.AppendLine(product.product\u id.Length.ToString())”

Dim RegexObj作为Regex RegexObj=New Regex(“^sb.AppendLine((.*.Length.ToString())$”)

作为字符串的Dim res res=RegexObj.Replace(str,“sb.AppendLine(“$1”“+product.product\u id.Length.ToString()))

在c#net中

字符串str=null; str=“sb.AppendLine(product.product\u id.Length.ToString())”

Regex RegexObj=默认值(Regex); RegexObj=newregex(“^sb\.AppendLine\(.*)\.Length\.ToString\(\)\)$”

字符串res=null;
res=RegexObj.Replace(str,“sb.AppendLine(\“$1\”+product.product\u id.Length.ToString())”

发布代码时,请尝试将其格式化为代码块。你可以把每行缩进4个或更多的空格,用`字符包装,或者高亮显示,然后点击编辑器上的{}按钮。谢谢Justin,我不知道。当你发布代码时,试着用代码块格式化它。你可以把每一行缩进4个或更多的空格,用`字符包装,或者只是突出显示,然后点击编辑器上的{}按钮。谢谢贾斯汀,我不知道。