Search code examples
c#.netregexphone-number

Phone number regex extraction from formatted string


Given the phone numbers are all on this format:

(999) 999-9999 Ext.9999"

I want to return everything to the second space, e.g.:

(999) 999-9999

Any ideas?


Solution

  • if your string is in s:

       string s = "(999) 999-9999 Ext.9999";
       string number = s.Split(" Ext")[0];