Skip to content

Instantly share code, notes, and snippets.

@krzysztofjablonski
Forked from fguillen/regex.irb
Created March 1, 2012 15:06
Show Gist options
  • Save krzysztofjablonski/1950343 to your computer and use it in GitHub Desktop.
Save krzysztofjablonski/1950343 to your computer and use it in GitHub Desktop.
Non Greedy Regex match
# By default ReGex will match the bigest occurrence:
ruby-1.9.2-p180 > "_one_ two _three_".scan(/_(.+)_/)
=> [["one_ two _three"]]
# But we can tell it to match all the smallest ones:
ruby-1.9.2-p180 > "_one_ two _three_".scan(/_(.+?)_/)
=> [["one"], ["three"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment