Reputation: 2689
How do I add the character -
within the preg_match?
preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string)
But it must be before the last .
within the string. I've tried just about everything I know here. I know that the -
needs to be escaped. So I tried to escape it in various places, but it's not working :(
argggg
Upvotes: 1
Views: 130
Reputation: 338228
Your knowlegde that the dash needs to be escaped is incomplete.
preg_match('#^(\w+/){0,2}\w+-\.\w+$#', $string)
It needs to be escaped in character classes, because it has a special meaning there, but it has no special meaning in the rest of the regex, so it needs no escaping here.
Upvotes: 3