progs/catastrophic/catastrophic.js
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 23 Aug 2020 23:44:44 +0100
changeset 745 7dc3643a0cc5
parent 741 e66bd5c563eb
child 753 d94fdbef1a4f
permissions -rwxr-xr-x
updated

#!/usr/local/bin/node

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