PaulWill
PaulWill

Reputation: 623

Remove numbers from beginning of string using regex

I am trying to find the right regex to remove just the numbers from the beginning of a string

>from
8012 name last name 123 456
6952332 name last 213 5695

>into
name last name 123 456
name last 213 5695

this is not good cus its matching all

 @"[\d-]"

Upvotes: 5

Views: 3909

Answers (1)

Steve
Steve

Reputation: 216353

You need to anchor your pattern to the beginning of the string ^

string pattern = @"^[0-9]+";   // or @"^\d+";
string source = "8012 name last name 123 456";
string newText  = Regex.Replace(source, pattern, "");

Upvotes: 7

Related Questions