开发者

preg_replace - PHP [closed]

开发者 https://www.devze.com 2023-01-11 12:30 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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

精彩评论

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