[英]regular expression-javascript
I want to get the string which comes between first :
and first .
我想获取 first
:
和 first 之间的字符串.
s:4332Hhj4j32hh432kjh.EF4324rf46543DSVC3443
I tried the following:我尝试了以下方法:
/:(.*?)\./g
But still it catches : and .但它仍然捕获 : 和 。
How can I exclude them?我怎样才能排除它们?
Here is my example: http://www.regexr.com/3busf这是我的例子: http : //www.regexr.com/3busf
Thanks谢谢
Use matches[1]
instead of matches[0]
:使用
matches[1]
而不是matches[0]
:
var re = /:(.*?)\\./g; var str = 's:4332Hhj4j32hh432kjh.EF4324rf46543DSVC3443'; var matches; while ((matches = re.exec(str)) !== null) { if (matches.index === re.lastIndex) { re.lastIndex++; } console.log(matches[0]); // ":4332Hhj4j32hh432kjh." console.log(matches[1]); // "4332Hhj4j32hh432kjh" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.