0

I need a regex to the format number/dot/number*2/dot/number*2 (1.10.50 for example) For that I created the regex \d{1}\.\d{2}\.\d{2}

But this regex matches with the following tests:

10.10.10 -> true

1.10.1000 -> true

Thanks for help

Olivier
  • 343
  • 2
  • 16
  • Try appending `$` to your regex. This indicates that the input string must end after the 5th digit: `\d{1}\.\d{2}\.\d{2}$`. This is called the end of string/line anchor. `^` is the the start of string/line anchor btw. – Good Night Nerd Pride Aug 30 '23 at 09:05
  • 3
    FYI `{1}` quantifier is useless in regex. – Hao Wu Aug 30 '23 at 09:07
  • Thanks, but it always works with '100.10.10' for example – Olivier Aug 30 '23 at 09:09
  • 2
    Use digit boundaries: `(?<!\d)\d\.\d{2}\.\d{2}(?!\d)`. Or if you mean to match the whole string, anchors: `^\d\.\d{2}\.\d{2}$`. Or - if you need whole word matching - use word boundaries: `\b\d\.\d{2}\.\d{2}\b`. – Wiktor Stribiżew Aug 30 '23 at 09:09

0 Answers0