Sunday 12 August 2018

regex - What is '?-mix' in a Ruby Regular Expression

mix is not the English word mix, it's options of Regexp.




See Regexp#to_s:




Returns a string containing the regular expression and its options (using the (?opts:source) notation.




In your example, m is for multiline mode, i is for case insensitive, and x is for extended mode. Options before the dash are on, those after are off (default). The question's example, ?-mix, has all options off.



You can turn them on like:




puts /^a$/mix
# =>(?mix:^a$)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...