Since you already know that you're searchning for
"My number is"
, you don't need to know what it is.
But because you made the effort to write a question, I guess you're actually looking for whatever comes before the spaces. So you could try this:
string input = "my number is -----------------------------------------890";
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(" [ 0-9]");
System.Text.RegularExpressions.Match match = regex.Match(input);
string key = input.SubString(0, match.Index);
The regular expression checks for a space followed by another space or number. So for this to work, there
- must be at least one space between
key
and the phone number
- must not be any numbers starting words within
key
.
Or, what about this one:
regex = new Regex("[0-9]{3,}");
Match match = regex.Match(input);
int numberIndex = match.Index;
string key = input.SubString(0, numberIndex);
key = key.Trim()
Ah, forget it all:
string input = "my number is -----------------------------------------890";
string key = input.Trim(new Char[]{' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});