I have this regex:
Regex myRegex = new Regex(@"^[a-zA-Z .:_-]+([0-9]+)[a-zA-Z .:_-]*+$");
and I would like to match a digit code this way:
- "Order No. 0123456 lorem ipsum" - MATCH 0123456 in Group 1
- "No. 0123456" - MATCH 0123456 in Group 1
- "Order 0123456" - MATCH 0123456 in Group 1
- "013456 lorem ipsum" - NO MATCH
This works here: https://regex101.com/
but not in .NET with C# as I have this exception:
"System.ArgumentException: parsing "^[a-zA-Z .:_-]+([0-9]+)[a-zA-Z .:_-]*+$" - Nested quantifier +.
at System.Text.RegularExpressions.RegexParser.ScanRegex()
at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache)
at System.Text.RegularExpressions.Regex..ctor(String pattern)
at Rextester.Program.AnalyzeFreetext(String freeText)
at Rextester.Program.Main(String[] args)"
Is there an alternative an maybe more elegant way to capture the digits between text (mandatory before digits, optional after).
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…