| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Sun, 01 Oct 2023 10:57:32 +0100 | |
| changeset 931 | c9d6b50345d7 | 
| parent 753 | 30ea6b01db46 | 
| 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) |