正则表达式[1 - 3][0 - 9] {4}(?:E [0 - 9] {6})?$
sample data
successful my registration id is #12345 E112233 (should match)
Successful my data is #22331 E001122 (should match)
failing 12345 (should not match)
预期OP
12345 E112233
22331 E001122
代码-
var content ="successful my registration id is #12345 E112233
Successful my data is #22331 E001122
failing 12345";
var regex = new Regex(@"[1-3]\d{4}([ ]E\d{6})?$",RegexOptions.Multiline);
var REG_ID = regex.Match(myStringData).Value;
1条答案
按热度按时间a14dhokn1#
您可以使用
请参见regex demo。
#
-首先查找#
((?<=#)
查找前面紧跟#
字符的位置)([1-3]\d{4}(?: E\d{6})?)
-然后捕获(至第1组):[1-3]\d{4}
-一个1
/2
/3
数字+四个数字(?: E\d{6})?
-空格+E
+六位数字的可选序列$
-字符串结束。