开发者

preg_replace - PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist

Closed 9 years ago.

开发者_StackOverflow中文版 Improve this question

having a bit of trouble with replacing things that are NOT 0-9A-Za-z[:space] because I cannot find a NOT metachar for preg_replace. Does anytone know if one exists and if not what is the best way to strip anything that is NOT alpha numeric or a space?


Use negated character classes:

/[^A-Za-z0-9 ]/

You could also use the \w escape sequence, which is equivalent to [a-zA-Z0-9_] (note the underscore). So your regex would look like

/[^\w ]/

Reference:

http://www.regular-expressions.info/charclass.html


More useful:

/[^A-Za-z0-9 ]+$/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜