Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to allow alphanumeric and dot

Tags:

regex

php

Hi I have a variable in a Silex route and we only allow alphanumeric values

->assert('hash','\w+')

I would like to also allow a dot in the variable, but my efforts at editing this regex have failed. Help greatly appreciated, thanks!

like image 897
Acyra Avatar asked Dec 01 '22 02:12

Acyra


1 Answers

Try using a character class ([…]), like this:

[\w.]+

For example:

->assert('hash','[\w.]+')
like image 184
p.s.w.g Avatar answered Dec 05 '22 16:12

p.s.w.g