Regexp.union
returns the following inspection:
Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
What does ?-mix:
mean?
What you're seeing is a representation of options on sub-regexes. The options to the left of the hyphen are on, and the options to the right of the hyphen are off. It's smart to explicitly set each option as on or off to ensure the right behavior if this regex ever became part of a larger one.
In your example, (?-mix:dogs)
means that the m
, i
, and x
options are all off whereas in (?i-mx:cats)
, the i
option is on and thus that subexpression is case-insensitive.
See the Ruby docs on Regexp Options:
The end delimiter for a regexp can be followed by one or more single-letter options which control how the pattern can match.
/pat/i
- Ignore case/pat/m
- Treat a newline as a character matched by ./pat/x
- Ignore whitespace and comments in the pattern/pat/o
- Perform #{} interpolation only oncei, m, and x can also be applied on the subexpression level with the
(?on-off)
construct, which enables options on, and disables options off for the expression enclosed by the parentheses.