escape static method Null safety

String escape(
  1. String text

Creates regular expression syntax that matches the input text.

If text contains regular expression reserved characters, the resulting regular expression matches those characters literally. If text contains no regular expression reserved characters, Dart returns the expression unmodified.

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

Use this method 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 to search for that exact 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);