0
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”,但它没有。

怎么了?

4

2 回答 2

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;
于 2012-11-26T13:29:40.670 回答
0

请尝试以下方法:

尽管 C# 转义略有不同,但在Rublar的参考资料。你可以测试一下。我相信你,如果你在正则表达式中必须使用 to_upper ,那会更好:)

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);
于 2012-11-26T14:02:43.343 回答