Site Archives

Escaping regular expression characters in an input string


When using input gathered from a user to create a regular expression, the user input may contain regular expression control characters such as ‘.’ and ‘*’. These need to be escaped so the regular expression engine treats them as literal characters.