Allow passing re flags to regex commands

This allows the regex behaviour to be adjusted, such as by setting
re.IGNORECASE in order to perform case-insensitive matching.