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?
Don't use a regular expression. Use Split(). Then concatenate the first two elements back together.
Where s contains the full sting. If truely "all on this format" exactly, then you could just take the first 14 characters:
string number = s.SubString(0, 14);
Or a bit more flexible, and safer:
var idx = s.IndexOf(" Ext");
//good idea to check if idx == -1
string number = s.SubString(0, idx);
Check out this one:
string s = "(999) 999-9999 Ext.9999";
string phonenumber1 = Regex.Replace(s, @"(?i)\s*ext\.\d+", "");
.Split methods proposed here.
extis in small letters ?