| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Sat, 16 May 2020 17:18:43 +0100 | |
| changeset 724 | b53b6d61fcb6 | 
| parent 701 | 81377a3eb717 | 
| permissions | -rw-r--r-- | 
| 614 | 1  | 
|
2  | 
||
3  | 
||
4  | 
// A case of catastrophic backtracking in JavaScript/Node.js  | 
|
5  | 
//  | 
|
6  | 
// regex: (a*)*b  | 
|
7  | 
// strings: aa...  | 
|
8  | 
//  | 
|
9  | 
// call with:  | 
|
10  | 
//  | 
|
| 701 | 11  | 
// $> node catastrophic.js 20  | 
| 614 | 12  | 
//  | 
13  | 
// call with timing as:  | 
|
14  | 
//  | 
|
| 701 | 15  | 
// $> time node catastrophic.js 25  | 
| 614 | 16  | 
|
17  | 
||
18  | 
const args = process.argv[2]  | 
|
19  | 
||
20  | 
var str = 'a'.repeat(args);  | 
|
21  | 
||
22  | 
console.log(str)  | 
|
23  | 
||
24  | 
var re = /^((a)*)*b$/;  | 
|
25  | 
||
26  | 
var res = re.test(str);  | 
|
27  | 
||
28  | 
console.log(res)  |