我有这个字符串,例如:
one two three four START four five four five six END seven
我想在其中搜索单词“four”以用REPLACED替换它,这将给出
one two three four START REPLACED five REPLACED five six END seven
我知道START(.*)END
会在分隔符和分隔符之间给出单词。
我试过了START(?<four>)END
,但它什么都没有。
我在Vbscript工作。
答案 0 :(得分:5)
(?<name>
适用于命名组。
您需要的是前瞻和后置断言,以匹配START.*
和.*END
前后条件,而不实际匹配它们。
Dim input = "one two three four START four five four five six END seven"
Dim output = Regex.Replace(input, "(?<=START.*)four(?=.*END)", "test")
收益率:one two three four START test five test five six END seven
答案 1 :(得分:0)
为什么要使用正则表达式?
Dim oldStr = "one two three four START four five four five six END seven"
Dim newStr = oldStr.Replace("four", "REPLACED")