New in Firefox 3 Non-standard sticky; matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes). This allows the match-only-at-start capabilities of the character "^" to effectively be used at any location in a string by changing the value of the lastIndex property.
function print(str){ document.write(str); document.write("<br/>"); } var text = "First line\nsecond line"; var regex = /(\S+) line\n?/y; var match = regex.exec(text); print(match[1]); // prints "First" print(regex.lastIndex); // prints 11 var match2 = regex.exec(text); print(match2[1]); // prints "Second" print(regex.lastIndex); // prints "22" var match3 = regex.exec(text); print(match3 === null); // prints "true"
ignoreCase:i
multiline:m
sticky:y
sticky什么意思
http://msdn.microsoft.com/zh-cn/library/yd1hzczs.aspx
sticky; matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes). This allows the match-only-at-start capabilities of the character "^" to effectively be used at any location in a string by changing the value of the lastIndex property.
function print(str){
document.write(str);
document.write("<br/>");
}
var text = "First line\nsecond line";
var regex = /(\S+) line\n?/y;
var match = regex.exec(text);
print(match[1]); // prints "First"
print(regex.lastIndex); // prints 11
var match2 = regex.exec(text);
print(match2[1]); // prints "Second"
print(regex.lastIndex); // prints "22"
var match3 = regex.exec(text);
print(match3 === null); // prints "true"