Skip to content

Instantly share code, notes, and snippets.

@fguillen
Created December 12, 2011 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fguillen/1466148 to your computer and use it in GitHub Desktop.
Save fguillen/1466148 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