我想用另一個集合替換標籤11 =和〜之間的所有字符。例11 = 1234〜應由11 = 56789〜代替。第一限定必須以字爲界,意義,111 =不應該成爲比賽C#正則表達式在分隔符之間取代
0
A
回答
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
相關問題
- 1. 正則表達式刪除分隔符之間的字符串
- 2. 正則表達式到分隔符之間的大寫
- 3. JAVA正則表達式返回分隔符之間的鏈
- 4. 正則表達式 - 分隔符之間的所有子串
- 5. 正則表達式捕獲分隔符之間的每一位
- 6. C++正則表達式。獲取帶分隔符的字符串
- 7. 正則表達式 - 在分隔線之間搜索/ *和* /之間的字符串
- 8. 用正則表達式分隔符
- 9. 正則表達式的分隔符
- 10. 正則表達式分隔字符串
- 11. 正則表達式:由分隔符
- 12. Swift正則表達式和分隔符
- 13. PHP正則表達式分隔符
- 14. 帶分隔符正則表達式
- 15. PHP的正則表達式/分隔符
- 16. 正則表達式街道分隔符
- 17. 正則表達式在分隔符之間查找兩個以上的字符
- 18. 正則表達式如何提取分隔符之間的字符串而不是雙分隔符
- 19. 替換分隔符之間的字符串中的字符 - 正則表達式
- 20. C# - 正則表達式 - 獲取兩行之間的字符串
- 21. 在C中分隔字符的正則表達式和方法#
- 22. C#正則表達式按分隔符分割
- 23. 正則表達式來提取分隔符內的字符串
- 24. 刪除兩個正則表達式之間的特殊字符分隔符
- 25. 正則表達式替換分隔符之間的文本在python
- 26. 任何事情之前和分隔符正則表達式後
- 27. 正則表達式提取之間u''
- 28. 涉及嵌套分隔符/正則表達式的正則表達式
- 29. 逗號分隔的時間正則表達式c#?
- 30. C++正則表達式令牌分隔符
嘗試新鮮事物? – BoltClock