encodeTextInRegex function

String encodeTextInRegex(
  1. String text
)

Encodes text to escape special characters, so it can be normal text when using as part of the regular-expression clause (~ and `~*).

By normal we mean the text matches exactly character-by-character. Any special characters in text, such as '.' and '*', will be encoded, so . matches ., no longer wildcard.

Example: `"name" ~* E'A-Z+${encodeRegexp(input)}'

Implementation

String encodeTextInRegex(String text)
=> text.replaceAllMapped(_reRegex, _encRegex);