Skip to content

Instantly share code, notes, and snippets.

@fguillen
Created December 12, 2011 09:21
Show Gist options
  • Select an option

  • Save fguillen/1466148 to your computer and use it in GitHub Desktop.

Select an option

Save fguillen/1466148 to your computer and use it in GitHub Desktop.

Revisions

  1. fguillen created this gist Dec 12, 2011.
    9 changes: 9 additions & 0 deletions regex.irb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # 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"]]