內字符序列的所有實例假設我有以下內容的文本文件:如何替換字符串
longtextwith some space and unicode escape like this \u003ca
我想要替換的\u003c
所有實例/ OCCURENCES /序列無視事實上,a
是尾隨的。就像「尋找一系列字符的所有實例,忽略情況並替換它」。
我想這已經沒有任何反應:
using (var sr = new StreamReader("1.txt"))
{
string result = sr.ReadToEnd();
result = Regex.Replace(result, @"\b\\u003c\b", "<", RegexOptions.IgnoreCase);
}
這個變體還會產生不是我想要的結果:
result = Regex.Replace(result, @"\\u003c", "<", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\u003c", "<", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\b\\u003c\b", "<", RegexOptions.IgnoreCase);
在Lua這一工作:str = string.gsub(str, '\\u003e', '>')
在這種情況下,我對.NET編碼和解碼unicode,ascii等提供的選項不感興趣。
使用正則表達式編輯工具,讓您調試正則表達式。問題必須在模式中。例如在使用@時你有雙倍\\。看到這個答案如果你不想購買RegExBuddy http://stackoverflow.com/questions/132405/free-alternative-to-regxbuddy – n00b