escapeRegex function

String escapeRegex(
  1. String str
)

Escapes special regex characters in str so that it can be used as a literal match inside of a RegExp.

The special characters are: \ ^ $ . | + [ ] ( ) { } as defined here: http://ecma-international.org/ecma-262/5.1/#sec-15.10

Implementation

String escapeRegex(String str) => str.splitMapJoin(_specialChars,
    onMatch: (Match m) => '\\${m.group(0)}', onNonMatch: (s) => s);