escapeForRegex method

String escapeForRegex()

Escapes characters in a string that have a special meaning in regular expressions.

Implementation

String escapeForRegex() =>
    // The regex finds any special regex character, and the callback prepends a backslash.
    replaceAllMapped(RegExp(r'[.*+?^${}()|[\]\\]'), (Match m) => '\\${m[0]}');