progs/catastrophic/catastrophic.js
changeset 741 e66bd5c563eb
parent 701 681c36b2af27
child 745 7dc3643a0cc5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/catastrophic/catastrophic.js	Mon Jul 27 11:02:48 2020 +0100
@@ -0,0 +1,28 @@
+
+
+
+// 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)