正则表达式 - 前三个后匹配数字

时间:2014-11-19 21:13:44

标签: c# .net regex

我有一些数字,例如

;201000129712 
;20100054129712 
;202343234 
;203234234325 
;204234325654 

我想排除第一个;20x并匹配其余数字。

到目前为止,这是我的尝试。

^;20([0-9])

^(;20\d)

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

2 个答案:

答案 0 :(得分:1)

您可以使用lookbehind正则表达式:

(?<=;20)\d+

RegEx Demo

答案 1 :(得分:1)

你很近:

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

您想要包含半冒号,然后是三位数,然后使用后引用捕获所有后续数字,直到行尾。

或者,如果您批量处理多行字符串:

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