I am trying to create regular expression that will validate simple patterns. Here a lists of valid and invalid patterns.
Valid:
foo, foo.bar, foo.bar.baz,
*, *.foo, foo.*, *.foo.*, *.foo.bar, foo.*.bar, foo.bar.*, *.foo.bar.*,
**, **.foo, foo.**, **.foo.**, **.foo.bar, foo.**.bar, foo.bar.**, **.foo.bar.**
And invalid:
<empty string>, null, false, true, foo bar baz,
.foo, foo., .foo.,
***, ***.foo, foo.***, ***.foo.*, foo.***.bar
So allowed marks are * and **.
I spent a lot of time trying to write a regexp for those patterns, and best solution was:
/(\.|^)(\w+|\*{1,2})(?=\.|$)/
But it doesn't check whole patten, just finds it parts, so I cannot validate using preg_match. Another problem is that .foo pattern is valid according to that regexp, but it shouldn't because of dot in the beginning.
What did I miss?