Reputation: 4254
I tried this regex syntax in http://gskinner.com/RegExr/ and seem working well.
^[a-z0-9-]+.([a-z]{2,4})$
the purpose is to match domain name(not containing http or https)
so i use preg_match( '/^[a-z0-9-]+.([a-z]{2,4})$/g', 'fathi-hadi.net' )
but always return false
i don't know why
Upvotes: 1
Views: 815
Reputation: 34867
When you turn on error reporting, you would've noticed preg_match
doesn't support the g
modifier:
Warning: preg_match() [function.preg-match]: Unknown modifier 'g'
So drop that and use:
preg_match('/^[a-z0-9-]+\.([a-z]{2,4})$/', 'fathi-hadi.net');
That will match. I also incorporated Gerald Schneider's comment about escaping the dot, which is a good point.
Upvotes: 2