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.
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.
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?
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");
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.
Bookmarks