VB2005:我已经花了几个小时看正则表达式,但好像无法理解如何在我的情况下使用.Replace。我正在寻找两个字段,然后我想用新值替换这些字段。所以我的字符串看起来像这样:
Dim myInputString as string ="RTEMP MIN<240 MAX<800"
我的正则表达式是
dim ptn as string = "RTEMP\s{17}MIN<(?<min>(\d|\s){1,3})\s{1,3}MAX<(?<max>(\d|\s){1,3})\s{1,12}"
Dim MyRegex As Regex = New Regex(ptn, RegexOptions.IgnoreCase)
这个功能很好用,它能够捕获我的两个字段。现在我有新的值。
dim newMin as integer = 300
dim newMax as integer = 999
但似乎无法找到一次性替换两个值的方法。
Dim result As String = MyRegex.Replace(myInputString, MyRegexReplace)
我应该把什么放在MyRegexReplace中?这是一个简单的两个值替换,但是我可能会有更多,所以想着肯定有办法可以做到这一点,但需要帮助。
谢谢 AGP
"(RTEMP\s{17}MIN<)(...)(\s{1,3}MAX<)(...)(\s{1,12})"
并替换为"\1{newMin}\3{newMax}\5"
, 在其中替换了 newMin 和 newMax。 - mathematical.coffee