当前位置:  编程技术>其它

关于IE的RegExp.exec的问题

    来源: 互联网  发布时间:2014-10-16

    本文导语:  代码如下: 代码如下: var st="A[B]C[D]E[F]G"; var reg =/[w]/ig; var s1 = st.replace(reg,""); var s2=[]; var arr; while((arr=reg.exec(st))!=null)s2.push(arr[0]); alert(s1); alert(s2.join("")); FF下正确显示,IE下S2为空. 网上查不到资料,请各位指点一二. 查询过程中得...

代码如下:
代码如下:

var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=reg.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));


FF下正确显示,IE下S2为空.

网上查不到资料,请各位指点一二.

查询过程中得了个意外收获
代码如下:

var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];

var arr;
while((arr=/[w]/ig.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));

该写法IE死循环RegExp的lastIndex没有得到更新

In some recent code, I'm using Javascript to parse through the result set of an AJAX call, which happens to be returning a full HTML page. Yes, ideally, I'd have an AJAX call return something usable like JSON, but in this case the PHP back-end code had to remain as is and the front-end adjust to handle the legacy HTML it returned.
I needed to grab a link (1 or more) from the returned HTML page so that I could immediately display those links in separate windows (each was a generated report). So, my first stab at this is shown in the following code example. Basically, we have setup a string to represent the returned HTML, in this case it contains 3 links; and we want to use the standard Javascript RegExp object's exec() method to grab the URLS (href parameter) for each of those links. In our example, we just print them out in an unordered list to see what we've captured. The important lines of code we'll be looking at are highlighted in the example below.
代码如下:

var s='
XnYnZn';
document.write('Found the following link URLs in the string:
    ');
    while (matches = /

    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • js正则表达式之input属性($_)RegExp对象属性介绍
  • gnu.regexp是什么东西
  • 正则(JS)re=new RegExp("^\d*$");与re=/^d*$/;之间区别?
  • js正则表达式讲解之index属性(RegExp对象)
  • vi 查找替换字符串之前要求确认,如何确认? %s/regexp/replacement/g
  • 特急!!!如何使用regexp来进行正则表达式的匹配?
  • javascript RegExp multiline多行匹配影响的^$
  • js正则表达式之RegExp对象之compile方法 编译正则表达式
  • RegExp对象的方法和属性
  • oracle正则表达式regexp_like的用法详解
  • js正则表达式之RegExp对象属性lastIndex,lastMatch,lastParen,lastContext,rightContext属性讲解
  • javascript RegExp对象(正则表达式)
  • javascript RegExp 对象属性与方法和应用
  • JavaScript 正则表达式之RegExp属性、方法及应用分析
  • asp的RegExp对象正则表达式功能用法[比较全]
  • JavaScript RegExp 正则表达式对象详细说明
  • mysql数据库replace、regexp的用法




  • 特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3