progs/catastrophic.js
author Christian Urban <urbanc@in.tum.de>
Thu, 26 Sep 2019 12:59:33 +0100
changeset 635 81b85ccfa40c
parent 614 3ed8ac396863
child 701 81377a3eb717
permissions -rw-r--r--
updated




// A case of catastrophic backtracking in JavaScript/Node.js
//
// regex: (a*)*b
// strings: aa...
//
// call with:
//
//  $> node catastrophic.py 20
//
// call with timing as:
//
//  $> time node catastrophic.py 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)