Created
October 26, 2011 07:49
-
-
Save gtzilla/1315719 to your computer and use it in GitHub Desktop.
Regex Test, consistent fail on every other when matching - or !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var raw_str_regex = "-([a-zA-Z0-9_]+)$"; | |
var regex = new RegExp(raw_str_regex, "gm"); | |
var lst = [ | |
"this is -not", | |
"this is -not", | |
"this is -not", | |
"this is -not", | |
"this is -not", | |
"this is -not" | |
]; | |
var check_okay = []; | |
console.log(regex); | |
var test_value = regex.test( lst[0] ); | |
console.log("test:", test_value, lst[0]); | |
var test_value1 = regex.test( lst[1] ); | |
console.log("test:", test_value1, regex.source, lst[1]); | |
if(test_value && test_value === test_value1) { | |
console.log("Yey!", RegExp.lastMatch); | |
} else { | |
console.log("FAILED!!!", RegExp.lastMatch) | |
} | |
console.log(regex); | |
for(var i=0; i<lst.length; i++) { | |
//regex.test(""); fixes it?? | |
var test_value = regex.test( lst[i] ); | |
console.log(test_value, lst[i]); | |
if(test_value === true) { | |
check_okay.push(test_value); | |
} | |
} | |
if(check_okay.length === lst.length) { | |
console.log("okay"); | |
} else { | |
console.log("FAILED!!!!!!", RegExp.lastMatch); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remove the global flag, no error | |
var raw_str_regex = "(-[a-zA-Z0-9_]+)$"; | |
var regex = new RegExp(raw_str_regex, "m"); | |
var lst = [ | |
"this is -not", | |
"this is -not", | |
"this is -not", | |
"this is -not", | |
"this is -not", | |
"this is -not" | |
]; | |
var check_okay = []; | |
console.log(regex); | |
var test_value = regex.test( lst[0] ); | |
console.log("test:", test_value, lst[0]); | |
var test_value1 = regex.test( lst[1] ); | |
console.log("test:", test_value1, regex.source, lst[1]); | |
if(test_value && test_value === test_value1) { | |
console.log("Yey!", RegExp.lastMatch); | |
} else { | |
console.log("FAILED!!!", RegExp.lastMatch) | |
} | |
console.log(regex); | |
for(var i=0; i<lst.length; i++) { | |
//regex.test(""); fixes it?? | |
var test_value = regex.test( lst[i] ); | |
console.log(test_value, lst[i]); | |
if(test_value === true) { | |
check_okay.push(test_value); | |
} | |
} | |
if(check_okay.length === lst.length) { | |
console.log("okay", RegExp.lastMatch); | |
} else { | |
console.log("FAILED!!!", RegExp.lastMatch); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node regex_compile_test2.js | |
/-([a-zA-Z0-9_]+)$/gm | |
test: true this is -not | |
test: false -([a-zA-Z0-9_]+)$ this is -not | |
FAILED!!! -not | |
/-([a-zA-Z0-9_]+)$/gm | |
true 'this is -not' | |
false 'this is -not' | |
true 'this is -not' | |
false 'this is -not' | |
true 'this is -not' | |
false 'this is -not' | |
FAILED!!! " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node regex_compile_test2.js | |
/(-[a-zA-Z0-9_]+)$/m | |
test: true this is -not | |
test: true (-[a-zA-Z0-9_]+)$ this is -not | |
Yey! -not | |
/(-[a-zA-Z0-9_]+)$/m | |
true 'this is -not' | |
true 'this is -not' | |
true 'this is -not' | |
true 'this is -not' | |
true 'this is -not' | |
true 'this is -not' | |
okay " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment