循环分组匹配的正则表达式例子
<script type="text/javascript">
var str = "@Beijing|北京|101@Shanghai|上海|102@Tianjin|天津|103@Chongqing|重庆|104@Haerbin|哈尔滨|105@Dalian|大连|106";
var pattern = /\@([^|]*)\|([^|]*)\|([^@]*)/g;
var mts;
while (mts = pattern.exec(str))
{
if (mts != null)
{
alert(mts[1]);
alert(mts[2]);
alert(mts[3]);
}
}
</script>
var str = "@Beijing|北京|101@Shanghai|上海|102@Tianjin|天津|103@Chongqing|重庆|104@Haerbin|哈尔滨|105@Dalian|大连|106";
var pattern = /\@([^|]*)\|([^|]*)\|([^@]*)/g;
var mts;
while (mts = pattern.exec(str))
{
if (mts != null)
{
alert(mts[1]);
alert(mts[2]);
alert(mts[3]);
}
}
</script>
- 没有相关文章
- 没有评论