Created
April 18, 2017 07:20
-
-
Save sushiljainam/88db06f006e1a47d0f511670485f3bb8 to your computer and use it in GitHub Desktop.
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
//regular expressions | |
v = /^a/.test('asdasaabb'); | |
console.log("/^a/.test('asdasaabb')", v); | |
console.log("/.*/.test('/^a+b+$/')", /.*/.test('/^a+b+$/')); | |
console.log("/^\/.*\/$/.test('/^a+b+$/')", /^\/.*\/$/.test('/^a+b+$/')); | |
console.log("/^\/.\/$/.test('/^a+b+$/')", /^\/.\/$/.test('/^a+b+$/')); | |
console.log("/^a/.test('/^a+b+$/')", /^a/.test('/^a+b+$/')); | |
console.log("/^a/.test('/^a+b+$/')", /^a/.test('/^a+b+$/')); | |
//s = readline(); | |
var rl = process.openStdin(); | |
var regex = /.*/; | |
rl.addListener("data", function(d) { | |
// note: d is an object, and when converted to a string it will | |
// end with a linefeed. so we (rather crudely) account for that | |
// with toString() and then trim() | |
var input = d.toString().trim(); | |
if(/^\/.+\/$/.test(input)){ | |
regex = new RegExp(input.slice(1,(input.length-1))); | |
console.log('regex changed to:'+regex); | |
}else | |
{ | |
var toTest = input; | |
console.log(regex+'.test("'+toTest+'") is : '+regex.test(toTest)); | |
} | |
if (d.toString().trim()==='end') { | |
rl.destroy(); | |
}; | |
}); | |
/*const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
rl.question('type a reqex (without slashes) ', | |
function (r) { | |
var regex = '/'+r+'/'; | |
rl.close(); | |
}); | |
rl.question('type examples to match', | |
function(m){ | |
console.log(regex.test(m)); | |
});*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment