escapeSpecialCharacters function

String escapeSpecialCharacters(
  1. String input, {
  2. bool extraEscape = false,
})

Implementation

String escapeSpecialCharacters(String input, {bool extraEscape = false}) {
  return input.replaceAllMapped(RegExp(r'[-[\]()*+?.,\\^$|#\s]'),
      (Match match) {
    return extraEscape ? '\\\\${match[0]}' : '\\${match[0]}';
  });
}