String testString = "Some text F4LE8AWMF87E and again some text";
Match myMatch = Regex.Match(testString, "\b(?=[a-zA-Z]*[0-9])(?=[0-9]*[a-zA-Z])[0-9a-zA-Z]{12,}\b");
myLabel.Text = testString.Substring(myMatch.Index, myMatch.Length);
myLabel现在应该显示" F4LE8AWMF87E"但它没有。
有什么问题?
答案 0 :(得分:1)
你必须在字符串文字中转义字符'\'。
String testString = "Some text F4LE8AWMF87E and again some text";
Match myMatch = Regex.Match(testString, @"\b(?=[a-zA-Z]*[0-9])(?=[0-9]*[a-zA-Z])[0-9a-zA-Z]{12,}\b");
myLabel.Text = myMatch.Value;
答案 1 :(得分:0)
请尝试以下方法:
在Rublar引用,尽管C#转义略有不同。你可以测试一下。我相信你,如果你必须在正则表达式中加上一个案例,这会使它变得更好:)
String testString = "Some text F4LE8AWMF87 and again some text";
Match myMatch =
Regex.Match(testString, "\b[a-zA-Z\d]{11,12}\b");
myLabel.Text = testString.Substring(myMatch.Index, myMatch.Length);