2011-11-03 40 views

回答

1

那麼你已經回答了你的問題:

resultString = Regex.Replace(subjectString, @"(?<=\b11=).*?(?=~)", "56789"); 

這是.NET,你可以把它翻譯成其他口味/引擎。

說明:

@" 
(?<=  # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) 
    \b  # Assert position at a word boundary 
    11=  # Match the characters 「11=」 literally 
) 
.   # Match any single character that is not a line break character 
    *?  # Between zero and unlimited times, as few times as possible, expanding as needed (lazy) 
(?=  # Assert that the regex below can be matched, starting at this position (positive lookahead) 
    ~   # Match the character 「~」 literally 
) 
" 
+0

如果我是reg表達式中的'earth',回答者是'stars'!謝謝。 –

+0

@ S.Sundararajan謝謝,但實際上這很基礎。我建議你閱讀一篇好的教程,例如http://www.regular-expressions.info/ – FailedDev

相關問題