Regular expression string does not contain 2 points in a row

I would like to know if this regular expression is correct to verify that the line does not start with a point, does not end with a point and contains at least one point anywhere, but not the beginning or end:

My problem is that I cannot figure out how to check if there are 2 dots in a row.

/ ^ ([^.]) + ([.]) +. * ([^.]) $ /

+4
source share
2 answers

It seems you need to use

^[^.]+(?:\.[^.]+)+$

Watch the regex demo

More details

  • ^ - beginning of line
  • [^.]+- 1 + characters other than .(so the first char cannot be .)
  • (?:\.[^.]+)+ - 1 or more (thus, the point inside the line must appear at least once):
    • \. - dot
    • [^.]+ - 1 + , . ( + char, ., , , 2 )
  • $ - .
+4

, :

^[^.]+(?:\.[^.]+){2,}$

, .

:

^[^.]+(?:\.[^.]+)+$

:

^[^.]+(?:\.[^.]+){1,2}$
+2

Source: https://habr.com/ru/post/1663843/


All Articles