How to remove first numeric characters from a string using regular expressions? string str = 20Be45;
Output -> Be45
How to remove first numeric characters from a string using regular expressions? string str = 20Be45;
Output -> Be45
This is the Regex
string text = "20Be45";
string replaced = Regex.Replace(text, "^[0-9]+", string.Empty);
BUT, I programmed for 15 years without using regexes, and you know what? I was happy, and my programs worked.
int i = 0;
while (i < text.Length && text[i] >= '0' && text[i] <= '9')
{
i++;
}
text = text.Substring(i);
This is another solution using the String.TrimStart method:
string text = "20Be45";
string replaced = text.TrimStart('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
Another non-Regex version:
var text = "20Be45";
var result = string.Concat(text.SkipWhile(char.IsDigit));