www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Runaway exec() in IE

  1. #1
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374

    resolved [RESOLVED] Runaway exec() in IE

    I am trying to get an exec to work on the following code:
    Code:
      i=0;
      alert("before exec");
      while ((result = /\\r\\n ?w:/g.exec(lines)) != null) { i++; }  //Counts number of lyric lines
      if (i > 1) lyricRegExp=/\\r\\n ?w:([^\\]*)/ ;  
      alert("after exec");
    If I find more than one occurrence of a line starting with "w:" (or has spaces before the "w"), I will need to change a regular expression used.

    The exec() runs fine in Firefox but hangs in Internet Explorer. The whole script I'm trying to test is abctst.htm on line 494. If anyone tries to run this click on Submit, my testing code is already filled in. The alerts shown will run first followed by about six more alerts before highlighted code is created in the bottom textarea.

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    You're recreating the regex object on each iteration, which means it's lastIndex isn't being incremented. Assign the regex to a variable before entering the loop. Not sure why FireFox doesn't behave the same way.

  3. #3
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374
    I've modified that part:
    Code:
      RegExp.input = lines; RegExp.multiline = true;                                                  ////////////////// New line
      i=0;
      alert("before exec");
      while ((result = /\\r\\n ?w:/g.exec()) != null) { i++; }  //Counts number of lyric lines   /////////Removed "lines" from exec()
      if (i > 1) lyricRegExp=/\\r\\n ?w:([^\\]*)/ ;  
      alert("i = " + i);
      alert("after exec");
    Setting the multiline was the last thing I did but it didn't help or hurt IE which now finds zero occurrences of w while Firefox finds all sixteen of them. The link in my first post now has these latest changes.

    Many thanks for looking at this? Are there other things I could try?

  4. #4
    Join Date
    Dec 2010
    Posts
    207
    Quote Originally Posted by wbport View Post
    I've modified that part:
    Code:
      RegExp.input = lines; RegExp.multiline = true;                                                  ////////////////// New line
      i=0;
      alert("before exec");
      while ((result = /\\r\\n ?w:/g.exec()) != null) { i++; }  //Counts number of lyric lines   /////////Removed "lines" from exec()
      if (i > 1) lyricRegExp=/\\r\\n ?w:([^\\]*)/ ;  
      alert("i = " + i);
      alert("after exec");
    Setting the multiline was the last thing I did but it didn't help or hurt IE which now finds zero occurrences of w while Firefox finds all sixteen of them. The link in my first post now has these latest changes.
    That is not what I suggested.
    Code:
    alert("before exec");
      
      var re = /\\r\\n ?w:/g
      
      while ((result = re.exec(lines)) != null) 
       { i++; }  //Counts number of lyric lines
      if (i > 1) 
       lyricRegExp=/\\r\\n ?w:([^\\]*)/ ;  
      alert("after exec");

  5. #5
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    374

    resolved

    Many thanks! What I now have is
    Code:
      i=0;
      var rw = /\\r\\n ?w:/g
      while ((result = rw.exec(lines)) != null) { i++; }  //Counts number of lyric lines
      if (i > 1) lyricRegExp=/\\r\\n ?w:([^\\]*)/ ;
    and have implemented it in the live version (ends in nwc instead of tst) without the extra alerts.

    Again, thanks clueful for looking into it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles