Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
please, kindly help to solve my following problem.
C#
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.
Posted

1 solution

Ahem:
C#
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
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.
 
Share this answer
 
Comments
Schatak 10-May-14 6:46am    
Good one :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900