author | Christian Urban <christian.urban@kcl.ac.uk> |
Fri, 18 Oct 2024 05:59:04 +0100 | |
changeset 970 | 1d4659dd83fe |
parent 753 | d94fdbef1a4f |
permissions | -rwxr-xr-x |
745 | 1 |
#!/usr/local/bin/node |
614 | 2 |
|
3 |
// A case of catastrophic backtracking in JavaScript/Node.js |
|
4 |
// |
|
5 |
// regex: (a*)*b |
|
6 |
// strings: aa... |
|
7 |
// |
|
8 |
// call with: |
|
9 |
// |
|
753 | 10 |
// $> ./catastrophic.js 20 |
614 | 11 |
// |
12 |
// call with timing as: |
|
13 |
// |
|
753 | 14 |
// $> time ./catastrophic.js 25 |
614 | 15 |
|
16 |
||
17 |
const args = process.argv[2] |
|
18 |
||
19 |
var str = 'a'.repeat(args); |
|
20 |
||
21 |
console.log(str) |
|
22 |
||
23 |
var re = /^((a)*)*b$/; |
|
24 |
||
25 |
var res = re.test(str); |
|
26 |
||
27 |
console.log(res) |