Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从字符串中删除除数字、字母、_(下划线)和 :(冒号)之外的所有内容
它是 PREG,我只遇到过 #\W#,但它删除了 :(冒号)。
任何帮助表示赞赏,谢谢!
[^\w:]+- 删除任何不是 ( [^...]) 字母、数字、下划线 ( \w) 或冒号 ( :) 的内容。
[^\w:]+
[^...]
\w
:
示例代码:
$ptn = "/[^\w:]+/"; $str = "Hello~~~ World+++: 123"; echo preg_replace($ptn, "", $str);
输出:HelloWorld:123
HelloWorld:123