Show/Hide Toolbars

You can specify options that control how the regular expression engine interprets a regular expression pattern.

By using the miscellaneous construct (?imnsx-imnsx), where a minus sign (-) before an option or set of options turns those options off. For example, (?i-mn) turns case-insensitive matching (i) on, turns multiline mode (m) off, and turns unnamed group captures (n) off. The option applies to the regular expression pattern from the point at which the option is defined, and is effective either to the end of the pattern or to the point where another construct reverses the option.

By using the grouping construct (?imnsx-imnsx:subexpression), which defines options for the specified group only.

The .NET Framework regular expression engine supports the following inline options.

Option

Description

i

Use case-insensitive matching.

m

Use multi-line mode. ^ and $ match the beginning and end of a line, instead of the beginning and end of a string.

n

Do not capture unnamed groups.

s

Use single-line mode.

x

Ignore un-escaped white space in the regular expression pattern.

Table 1: Regular expression options

Pattern

Matches

\b(?i)a(?-i)a\w+\b

"aardvark", "aaaAuto" in "aardvark AAAuto aaaAuto Adam breakfast"

For an example, see the "Multiline Mode" section in Regular Expression Options.


For an example, see the "Explicit Captures Only" section in Regular Expression Options.


For an example, see the "Single-line Mode" section in Regular Expression Options.


\b(?x) \d+ \s \w+

"1 aardvark", "2 cats" in "1 aardvark 2 cats IV centurions"

Table 2: Examples for regular expression options

© 2021 AFRY Austria GmbH, www.redbex.com