Click here to Skip to main content
15,891,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can anybody give me the regular expression for a string followed by a date.I can use
this regular expression in c# code page.

for example "Phone Number : 123-456-7890","Phone Number : 123.456.7890","Phone Number : (123) 456 7890" etc.


Thanks
Posted
Updated 25-Apr-12 0:22am
v2
Comments
sjelen 25-Apr-12 6:58am    
There is no universal regex for this, you must specify exactly all formats you want to match.

Sounds like common pattern. There a lot of examples which ready for use, for example here:
Using Common Patterns[^]
 
Share this answer
 
Well, for the examples you give above the next pattern would apply.


^(Phone Number\s:\s)(((\d{3}-){2}\d{4})|(((\d{3}\d){2}\d{4}))|(\(\d{3}\)\s{1}\d{3}\s{1}\d{4}))$

I had a more compact expression but it gave me the opportunity to match mixes of the three examples and I have no idea if that is what you want.

It will probably not cover every format you want to support, but it gives you a good starting point.

Hope it helps!
 
Share this answer
 

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