# Do I need to add code that escapes the control of the regexp symbols?

For example, String subtraction

There are answers with a regexp. And there are answers without regexp.

But answers with regexp works incorrect when strings contains the regexp control symbols. Yes, author of this question make the rule that the strings contains alphanumeric + spaces only. What about common case? Do I need to add code that escapes the control of the regexp symbols? Are there a common PGCC rule about it?

• string.indexOf(substring)
• string.search(substring)
The search method is shorter. But when a string is passed to it, it's implicitly coerced to a regular expression. Therefore, you can't use .search() if the substring may result in an invalid regular expression, and you must use .indexOf() instead.