从字符串中删除非字母数字字符
我有一个 PHP 字符串,我希望它与正则表达式 [A-Za-Z0-9] 匹配。我该怎么做?
I have a string in PHP and I want it to match the regex [A-Za-Z0-9]. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您的意思是,在正则表达式中使用
az
而不是aZ
,但您可以使用preg_replace
它采用模式 (
[a-zA-Z0 -9]
),替换(""
)和主题($string
)并返回新字符串($new_string
)I am assuming you meant,
a-z
instead ofa-Z
, inside of your regex, but you can usepreg_replace
It takes as arguments the pattern (
[a-zA-Z0-9]
), replacement (""
) and the subject ($string
) and returns the new string ($new_string
)\W
是[^a-Z0-9_]
的快捷方式。可能不是很有帮助,因为它也允许下划线,但我想让你知道。\W
is a shortcut for[^a-Z0-9_]
. May not be extremely helpful as it allows underscores too, but thought I'd let you know.