可能重复:
preg_replace除了数字、字母、句点和斜线之外的所有内容?
我有一个字符串,我想从该字符串中替换除之外的所有字符
- 所有字母
- 所有数字
- @
简单预处理替换为空字符串:
preg_replace('/[^'w@,.;]/', '', $string);
[^] represents a list of characters NOT to match
'w Word character (abcABC0-9_)
,.; as the characters themselves
怎么样:
preg_replace('/[^'pL'pN@,.;]+/', '', $string);
'pL
是字母的unicode属性'pN
是数字的unicode属性