论坛's Archiver

无心石 发表于 2008-6-10 01:34

我想用正则表达式匹配位于两个圆点中间的一段数字,例如“.123456.”  ,但我不想包括圆点在内。所以使用了包括前向断言和后向断言的正则表达式<br />/(?&lt;=\.)\d+(?=\.)/g<br /><br />但是firebug报错,提示<br />invalid quantifier ?&lt;=\.)\d+(?=\.)<br /><br />我想请教一下是因为火狐不支持正则表达式的断言吗?

sunwan 发表于 2008-6-10 09:58

<!--quoteo(post=129737:date=2008年6月10日 1&#58;34:name=无心石)--><div class='quotetop'>引用 (无心石 @ 2008年6月10日 1&#58;34) <a href="index.php?act=findpost&pid=129737"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->我想用正则表达式匹配位于两个圆点中间的一段数字,例如“.123456.”  ,但我不想包括圆点在内。所以使用了包括前向断言和后向断言的正则表达式<br />/(?&lt;=\.)\d+(?=\.)/g<br /><br />但是firebug报错,提示<br />invalid quantifier ?&lt;=\.)\d+(?=\.)<br /><br />我想请教一下是因为火狐不支持正则表达式的断言吗?<!--QuoteEnd--></div><!--QuoteEEnd--><br />印象中应该是支持的,可能你语句中有错误,报错的提示中好像少了个“(”。

无心石 发表于 2008-6-10 11:36

看表面好像火狐是这样认为的。但是正则我都写上来了,没有缺啊。我就郁闷了。。

sunwan 发表于 2008-6-10 14:26

<!--quoteo(post=129757:date=2008年6月10日 11&#58;36:name=无心石)--><div class='quotetop'>引用 (无心石 @ 2008年6月10日 11&#58;36) <a href="index.php?act=findpost&pid=129757"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->看表面好像火狐是这样认为的。但是正则我都写上来了,没有缺啊。我就郁闷了。。<!--QuoteEnd--></div><!--QuoteEEnd--><br />经实际测试,fx3只支持(?=),不支持(?&lt;=),可能是个bug吧。

无心石 发表于 2008-6-12 13:44

就是说只支持后向,不支持前向吧。看来只得用其他的方法了。另外想请教一下,逆向引用到底是用&quot;\1&quot;还是用&quot;$1&quot;?

sunwan 发表于 2008-6-13 10:28

<!--quoteo(post=130024:date=2008年6月12日 13&#58;44:name=无心石)--><div class='quotetop'>引用 (无心石 @ 2008年6月12日 13&#58;44) <a href="index.php?act=findpost&pid=130024"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->就是说只支持后向,不支持前向吧。看来只得用其他的方法了。另外想请教一下,逆向引用到底是用&quot;\1&quot;还是用&quot;$1&quot;?<!--QuoteEnd--></div><!--QuoteEEnd--><br />在正则表达式里用&quot;\1&quot;,在同一个语句里用&quot;$1&quot;(没试过),在后面的语句里用&quot;RegExp.$1&quot;。

无心石 发表于 2008-6-14 14:44

不是很清楚,不过这个我自己可以尝试一下。发现我的那段代码在IE下出错了,还要不知道是哪里出问题,IE就一大垃圾。。

页: [1]

© 2004-2009 Mozest.com