progs/catastrophic.js
author Christian Urban <urbanc@in.tum.de>
Thu, 26 Sep 2019 10:59:52 +0100
changeset 632 b7b91158eded
parent 614 be065677c8f1
child 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.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)