We sometimes need to filter strings which contains two or more dots, Regular expression is straight forward way to do this task.

This regex pattern matches strings with two or more dots
.*\..*\..*

How it works?
"."  matches any character except line-breaks
"*"  repeats previous tokens 0 or more times
"\." matches a single dot, slash is used for escape

So just read this regex pattern from left to right

.* Match any character and continue matching until next token
test.example.com

(\.) Match a single dot
test.example.com

.* Again, any character and continue matching until next token
test.example.com

\. Matches a single dot
test.example.com

.* Matches any character and continue matching until next token
test.example.com

Depending on application you need to escape "\" too, that case this pattern will become,
.*\\..*\\..*

Demo:
RegExr

 


Comments (0)
Leave a Comment

loader Posting your comment...