escape method Null safety

String escape(
  1. String text

Creates regular expression syntax that matches text.

If text contains characters that are meaningful in regular expressions, the resulting regular expression will match those characters literally. If text contains no characters that have special meaning in a regular expression, it is returned unmodified.

The characters that have special meaning in regular expressions are: (, ), [, ], {, }, *, +, ?, ., ^, $, | and \.

This method is mainly used to create a pattern to be included in a larger regular expression. Since a String is itself a Pattern which matches itself, converting the string to a regular expression isn't needed in order to search for just that string.

print(RegExp.escape('')); // dash@example\.com
print(RegExp.escape('a+b')); // a\+b
print(RegExp.escape('a*b')); // a\*b
print(RegExp.escape('{a-b}')); // \{a-b\}
print(RegExp.escape('a?')); // a\?


external static String escape(String text);