progs/catastrophic/catastrophic.js
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 17 Aug 2020 17:42:37 +0100
changeset 744 a33ce6c8e2c3
parent 741 6512884e03b4
child 745 905b60a029bf
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)