js正则使用XRegXep库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lxfHaHaHa/article/details/79319549

js正则本身不支持unicode的一些特殊用法,比如/\pP/ 这种可以匹配全部标点符号的用法,这里推荐一个正则库,XRegXep,如下是一个使用xregxep去除所有标点符号的js正则例子:


<script src="https://unpkg.com/[email protected]/xregexp-all.js"></script>
<script type="text/javascript">
    function pa(str){
        var re=new XRegExp("\\p{P}","g")
        str=XRegExp.replace(str,re,'')
        console.log(str)
    }
    pa("gh看 看88,.;:;gh")
</script>

这里写图片描述

如下是他的api: http://xregexp.com/api/

猜你喜欢

转载自blog.csdn.net/lxfHaHaHa/article/details/79319549