progs/catastrophic.js
author Christian Urban <urbanc@in.tum.de>
Tue, 28 Jan 2020 12:23:53 +0000
changeset 709 c112a6cb5e52
parent 701 681c36b2af27
permissions -rw-r--r--
updated




// A case of catastrophic backtracking in JavaScript/Node.js
//
// regex: (a*)*b
// strings: aa...
//
// call with:
//
//  $> node catastrophic.js 20
//
// call with timing as:
//
//  $> time node catastrophic.js 25


const args = process.argv[2]

var str = 'a'.repeat(args);

console.log(str)

var re = /^((a)*)*b$/;

var res = re.test(str);

console.log(res)