php - Regex matching if maximum two occurrences of dot and dash -


i need regular expression match string containing @ 2 dashes , 2 dots. there not have dash nor dot, if there 3+ dashes or 3 dots or both 3+ dashes , 3+ dots, regex must not match string.

intended use in php.
know of easy alternatives using php functions, used in large system allows filtering using regular expressions.

example string matched:
hello-world.com

example string not matched:
www.hello-world.easy.com or hello-world-i-win.com

is matching expectations?

(?!^.*?([.-]).*\1.*\1.*$)^.*$ 

see here on regexr

(?!^.*?([.-]).*\1.*\1.*$) negative lookahead. matches first .- put in capture group 1, , checks if there 2 more of them using hte backreference \1. found three, expression not match anymore.

^.*$ matches start end, if negative lookahead has not matched.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -