I need to capture strings containing more than one dot. String will mostly contains domain names like example.com, fun.example.com, test.funflys.com.
How can I do this using regex
?
You should escape dot's because they have special meaning.
So, that regex would be;
.*\..*\..*
But you should be careful that \
is possibly have a special meaning on your programming language too, you may be have to escape them also.
This is with JavaScript.
var regex = /(\..*){2,}/;
regex.test("hello.world."); // true
regex.test("hello.world"); // false
regex.test("."); // false
regex.test(".."); // true
It searches for the pattern 'dot followed by anything (or nothing)', repeated 2 or more times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With