正则表达式允许字母数字和点 [英] Regex to allow alphanumeric and dot

查看:68
本文介绍了正则表达式允许字母数字和点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Silex 路由中有一个变量,我们只允许使用字母数字值

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!

推荐答案

尝试使用 字符类 ([…]),像这样:

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

[\w.]+

例如:

->assert('hash','[\w.]+')

这篇关于正则表达式允许字母数字和点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆