equal
deleted
inserted
replaced
|
1 /// A case of catastrophic backtracking in Dart |
|
2 ///--------------------------------------------- |
|
3 /// example provided by Martin Todorov |
|
4 /// |
|
5 /// regex: (a*)*b |
|
6 /// strings: aa...a |
|
7 /// |
|
8 /// run with |
|
9 /// |
|
10 /// dart catastrophic.dart n |
|
11 |
|
12 |
|
13 main(List<String> args) { |
|
14 final n = int.parse(args[0]); |
|
15 final evilRegex = RegExp("(a*)*b"); |
|
16 |
|
17 for(int i = 1; i <= n; i++) { |
|
18 final toMatch = "a" * i; |
|
19 final stopwatch = Stopwatch()..start(); |
|
20 evilRegex.hasMatch(toMatch); |
|
21 print("$i a's matched in ${stopwatch.elapsed}"); |
|
22 } |
|
23 } |