Skip to content

Instantly share code, notes, and snippets.

@uu59
Last active December 16, 2015 06:48
Show Gist options
  • Save uu59/5393633 to your computer and use it in GitHub Desktop.
Save uu59/5393633 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
var re = /a/ig;
["abc", "abc", "abc", "abc"].forEach(function(s, i){
if(re.test(s)){
console.log("true", i, s, re.lastIndex);
}else{
console.log("false", i, s, re.lastIndex);
}
});
</script>
Result: (Chrome 26, Firefox 19 on Mac):
<pre>
true 0 abc 1 a.html:14
false 1 abc 0 a.html:16
true 2 abc 1 a.html:14
false 3 abc 0 a.html:16
</pre>
Refs: <a href="https://developer.mozilla.org/ja/docs/JavaScript/Reference/Global_Objects/RegExp/exec">https://developer.mozilla.org/ja/docs/JavaScript/Reference/Global_Objects/RegExp/exec</a>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment