MaylorTaylor
MaylorTaylor

Reputation: 5051

Regex - match digits after first three

I have some numbers such as

;201000129712 
;20100054129712 
;202343234 
;203234234325 
;204234325654 

And i want to exclude the first ;20x and match the rest of the numbers.

Here are my attempts so far.

^;20([0-9])

^(;20\d)

^[\;]\d{2}?\d

Upvotes: 1

Views: 73

Answers (2)

Greg Burghardt
Greg Burghardt

Reputation: 18888

You are close:

 Match match = Regex.Match(input, @"^;\d{3}(\d+)$");

You want to include the semi colon, then three digits, then capture all subsequent digits using a back reference until the end of the line.

Or if you are bulk processing a multi line string:

 MatchCollection matches = Regex.Matches(input, @"^;\d{3}(\d+)$");

Upvotes: 1

anubhava
anubhava

Reputation: 786136

You can use lookbehind regex:

(?<=;20)\d+

RegEx Demo

Upvotes: 1

Related Questions