Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression: Section names with unknown length?

Tags:

c#

regex

I have a text block that is formatted like this:

1.2.3.4.5 or 1.2222.3.4.5 or 1 or 1.2 etc

An unknow number of numbers and dots (sections of a legal document)

How can I capture the full section (1.2.3.4.5) into a group?

I use C# but any regex is fine, aI can translate it.

like image 545
Ian Vink Avatar asked Mar 10 '26 20:03

Ian Vink


1 Answers

UPDATED

Use this Regex:

Regex.Matches(inputString, @"\d[\.\d]*(?<!\.)");

explain:

\d                       digits (0-9)

[.\d]*                   any character of: '.', digits (0-9) 
                         (0 or more times, matching the most amount possible))

(?<! subexpression)      Zero-width negative lookbehind assertion.
like image 111
Ria Avatar answered Mar 13 '26 10:03

Ria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!