match method
Returns date matches for the password
.
A "date" is recognized as:
- any 3-tuple that starts or ends with a 2- or 4-digit year,
- with 2 or 0 separator chars (1.1.91 or 1191),
- maybe zero-padded (01-01-91 vs 1-1-91),
- a month between 1 and 12,
- a day between 1 and 31.
Note: this isn't true date parsing in that "feb 31st" is allowed, this doesn't check for leap years, etc.
Recipe: Start with regex to find maybe-dates, then attempt to map the integers onto month-day-year to filter the maybe-dates into dates. Finally, remove matches that are substrings of other matches to reduce noise.
Note: instead of using a lazy or greedy regex to find many dates over the full string, this uses a ^...$ regex against every substring of the password - less performant but leads to every possible date match.
Implementation
@override
List<List<DateMatch>> match(String password) {
final List<DateMatch> matches = <DateMatch>[
..._matchesWithSeparator(password),
..._matchesWithoutSeparator(password),
];
return <List<DateMatch>>[_filterNoise(matches)];
}