Need a regex pattern to match all of the following:
hello
hello.
hello.cc
I tried \b\w+\.?\w+?\b
, but this doesn't match "hello."
(the second string mentioned above).
Need a regex pattern to match all of the following:
hello
hello.
hello.cc
I tried \b\w+\.?\w+?\b
, but this doesn't match "hello."
(the second string mentioned above).
The problem is that you enforce the word boundary \b
after the dot, which doesn't match and the fact that you require at least one character after with \w+?
(lazy matching!).
Try this instead:
\b\w+\.?(\w+\b)?
https://regex101.com/r/lX1aE0/1
For more explanations about word boundaries, check this link
http://www.regular-expressions.info/wordboundaries.html
This is about as simple as I can get it:
See demo