escape brackets in regex python 1

escape brackets in regex python

r'\b\[harry\]\b'

Here is what the above code is Doing:
1. We’re using the re.compile() function to create a Regex object.
2. We’re passing the raw string to re.compile().
3. We’re using the re.IGNORECASE flag to make the regex case-insensitive.
4. We’re using the re.VERBOSE flag to ignore whitespace and comments inside the regex string.
5. We’re using the re.DOTALL flag to make the dot character match all characters, including the newline character.
6. We’re using the re.MULTILINE flag to make the caret and dollar character match the beginning and end of each line, not just the entire string.

Similar Posts