MULTILINE = INT2FIX(ONIG_OPTION_MULTILINE)
EXTENDED = INT2FIX(ONIG_OPTION_EXTEND)
IGNORECASE = INT2FIX(ONIG_OPTION_IGNORECASE)
ext/json/lib/json/add/core.rb lib/yaml/rubytypes.rb re.c
Check out this simple example:
"Hello Ruby friend".sub(/^(.*)e/, 'X') # => "Xnd" "Hello Ruby friend".sub(/^(.*?)e/, 'X') # => "Xllo Ruby friend"
The question mark turns the dotstar into non-eager mode which means it will halt on the first subsequent “e” rather than the last one. This comes in handy e.g. for Cucumber step definitions.
Okay, but not really nice:
/^I am using rvm "([^\"]*)" with gemset "(.*)"$/
Much more readable and consistent equivalent to the above:
/^I am using rvm "(.*?)" with gemset "(.*?)"$/
If you want to loop through the matches of a regular expression, String#scan is your friend. You can do something like this:
matches = '12345'.scan(/\d/) matches.each do |m| puts m end # => 1 # => 2 # => 3 # => 4 # => 5