正则表达式匹配一些特殊的字符

时间:2013-04-05 01:54:38

标签: php regex special-characters

我有这样的字符串:

  hello this is my_string is-very-cool & another stuff

如何通过所有特殊字符爆炸(?)我的字符串,但允许空格, - 和_?

任何想法?

1 个答案:

答案 0 :(得分:3)

preg_split('/[^\w -]/', $string)

这将拆分任何非a-z,0-9,_, - 或空格。