<p>I want to use input from a user as a regex pattern for a search over some text.  It works, but how I can handle cases where user puts characters that have meaning in regex?</p>
<p>For example, the user wants to search for Word <code>(s)</code>: regex engine will take the <code>(s)</code> as a group.  I want it to treat it like a string <code>&quot;(s)&quot; </code>.  I can run <code>replace</code> on user input and replace the <code>(</code> with <code>\(</code> and the <code>)</code> with <code>\)</code> but the problem is I will need to do replace for every possible regex symbol.</p>
<p>Do you know some better way ?</p>

Use the
```
re.escape()
```
function for this:
4.2.3
```
re
```
Module Contents
escape(string)
Return string with all non-alphanumerics backslashed; this is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it.
A simplistic example, search any occurence of the provided string optionally followed by 's', and return the match object.
```
```
def simplistic_plural(word, text):
    word_or_plural = re.escape(word) + 's?'
    return re.match(word_or_plural, text)
```
```