Created
December 12, 2011 09:21
-
-
Save fguillen/1466148 to your computer and use it in GitHub Desktop.
Non Greedy Regex match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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