js 正则表达式,分组非捕获
Posted 潇水鱼米
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 正则表达式,分组非捕获相关的知识,希望对你有一定的参考价值。
定位一个字符串中,匹配与定位重复字符中的最后一个字符:
例子:
<script type="text/javascript">
var str="http://www.cnblogs.com/cn-coder//img.ipg";
var patt1 = /\\/\\/(?!.*\\/\\/)/ig;
document.write(str.replace(patt1,"/"));//http://www.cnblogs.com/cn-coder/img.ipg
</script>
var str="http://www.baidu.com/xxxx//aaa/bbb/img.ipg"; var patt1 = /\\/\\/(?!.*\\/)/ig; document.write(str.replace(patt1,"/"));
另一种方式:
document.write("<BR>");
var str2="http://www.baidu.com//xxxx//img.ipg";
var patt2 =new RegExp(\'/(?!.*\\/\\/)/\',\'ig\');
document.write(str2.replace(patt2,"/"));
以上是关于js 正则表达式,分组非捕获的主要内容,如果未能解决你的问题,请参考以下文章