正则表达式的问题 [英] problem with regular expressions
本文介绍了正则表达式的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助解决我的下列问题。
Hi,
please, kindly help to solve my following problem.
string str = "\"phone-number\"";
string str1 = "<div class=" + str + ">" + "(101) 1010-1234" + "</div>";
string str2 = "<div class=\"phone-number\"><\\(\\d{3}\\) \\d{3}\\-\\d{4}/div>";
Match _match = Regex.Match(str1, str2);
string value = _match.Value;
Console.WriteLine(value);
我没有得到任何价值。
拜托,如果我错了,请帮我纠正我的代码。
先谢谢。
I am not getting any value.
please, help me to correct my code if i am wrong.
Thanks in advance.
推荐答案
Ahem:
Ahem:
string str1 = "<div class=" + str + ">" + "(101) 1010-1234" + "</div>";
string str2 = "<div class=\"phone-number\"><\\(\\d{3}\\) \\d{3}\\-\\d{4}/div>";
仔细观察:
Look closely:
\\d{3}\\-\\d{4}
是三位数,后跟一个连字符,后跟四位数。
Is three digits, followed by a hyphen, followed by four digits.
1010-1234
四位数后跟一个连字符,后跟四位数。
获取 Expresso [ ^ ] - 它是免费的,它会检查并生成正则表达式。
Is four digits, followed by a hyphen, followed by four digits.
Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
这篇关于正则表达式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文