如何与正则表达式匹配除“-"以外的所有特殊字符在PHP中? [英] How to match with regex all special chars except "-" in PHP?

查看:364
本文介绍了如何与正则表达式匹配除“-"以外的所有特殊字符在PHP中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何匹配PHP中除char -之外的所有特殊"字符(如+_*&^%$#@!~)?

How can I match all the "special" chars (like +_*&^%$#@!~) except the char - in PHP?

我知道\W会匹配包括-在内的所有特殊"字符.

I know that \W will match all the "special" chars including the -.

关于Unicode字母的任何建议吗?

Any suggestions in consideration of Unicode letters?

推荐答案

  • [^-]不是您想要的特殊字符
  • [\W]都是已知的特殊字符
  • [^\w]都是特殊字符-听起来还不错吗?
    • [^-] is not the special character you want
    • [\W] are all special characters as you know
    • [^\w] are all special characters as well - sounds fair?
    • 因此,[^\w-]是两者的组合:所有特殊"字符,但没有-.

      So therefore [^\w-] is the combination of both: All "special" characters but without -.

      这篇关于如何与正则表达式匹配除“-"以外的所有特殊字符在PHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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