Disabling mode modifiers

To disable a previously enabled mode, we can place a hyphen (-) before the modifier symbol anywhere in your regular expression.

Let's look at some examples.

To disable DOTALL, we can use the following regex:

    (?-s) 

To disable ignore case matching, we can use the following regex:

    (?-i) 

To disable the MULTILINE mode, we can use the following regex:

    (?-m)

To disable both ignore case and MULTILINE mode, we can use the following regex:

    (?-im)

To disable the ignore case, DOTALL, and MULTILINE modes, we can use the following regex:

    (?-ism)

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.