[英]PHP Regex add certain characters
I have the following regex that allows any letter and number (and I think uppercase too)! 我有以下允许任何字母和数字的正则表达式(我也认为是大写)!
What I need is to allow certain characters such as a - value and only that. 我需要的是允许某些字符,例如-值,仅此而已。
How would I insert that into this? 我该如何插入呢?
$reg = preg_replace('/[^a-z0-9 ]/i', '', $reg);
You can add additional characters inside the brackets like this: 您可以在方括号内添加其他字符,如下所示:
$reg = preg_replace('/[^a-z0-9 \-]/i', '', $reg);
If you meant that you want the expression inside the brackets or a minus, you can use this: 如果您想将表达式放在方括号内或减号内,则可以使用以下命令:
$reg = preg_replace('/([^a-z0-9 ]|\-)/i', '', $reg);
Not tested, but I think thats it. 未经测试,但我认为就是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.