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.
我想要一些 perl 正则表达式来替换任何非单词字符,如下所示:
s/\W//g;
但是,如果后面有两个冒号::,我不想替换它们。有谁知道如何做到这一点?谢谢!
::
/\W/是/[^\w]/,所以/[^\w:]/会删除除冒号之外的所有非单词字符。
/\W/
/[^\w]/
/[^\w:]/
您还想删除单独的冒号 ( /(?<!:):(?!:)/),所以最终的解决方案是
/(?<!:):(?!:)/
s/[^\w:]|(?<!:):(?!:)//g;