Combine re flags re.IGNORECASE, re.MULTILINE and re.DOTALL

Viewed 982

Can anyone tell me if I can combine flags like re.IGNORECASE, re.MULTILINE and re.DOTALL for regular expression matching?

r = re.compile(regex, re.IGNORECASE | re.MULTILINE | re.DOTALL)

I need to match an entire paragraph or an expression in one line according to the use case.

1 Answers

Yes, you can combine regex flags with |.

The documentation https://docs.python.org/3/library/re.html#re.compile specifically says:

The expression’s behaviour can be modified by specifying a flags value. Values can be any of the following variables, combined using bitwise OR (the | operator).

Related