Add Comments To Regex With Free-Spacing
Ruby's regex syntax supports a Free-Spacing mode. When this mode is enabled, all the literal whitespace in the regular expression is ignored and comments can be included at the end of lines. This is enabled by appending the x
option at the end of the regex.
Here is a regex with Free-Spacing mode enabled (see the x
at the end).
Though it's enabled, it is not really being used.
Here is the same regular expression, but this time I've spaced it out and added comment annotation to make the regex easier to understand.
To be sure the extra space and comments aren't messing things up, here is some code to test it out.
Last updated