Search code examples
.netregexdigits

Regex for matching digits followed by . (dot) then digits followed by . and so on


Currently I have this regex: [\d\.]+ I'm testing it with Regex Hero. You can check it working here.

It correctly reports 5 matches for these values:

1.1.4.3.
11.1.2.4.4.4.5
2
4.4
2.1.1

The problem is that it also matches the final . in the first value 1.1.4.3.

How can I exclude this last . and only match the value 1.1.4.3?


Solution

  • ^\d+(\.\d+)*$
    

    Should work, assuming two consecutive .s aren't allowed. Otherwise, just change the \. to \.+.