method
match
match(p1)
public
Register or
log in
to add new notes.
Oleg -
March 5, 2009
svoop -
February 10, 2009
6 thanks
String#match will match single token only
>> s = "{{person}} ate {{thing}}" => "{{person}} ate {{thing}}" >> r = /\{\{(.*?)\}\}/ => {{}} >> s.match(r).captures => ["person"]
Using String#scan pulls out all tokens you were searching for:
>> s.scan(r).flatten => ["person", "thing"]
0 thanks
Cheat Sheet
I have written a short introduction and a colorful cheat sheet for Perl Compatible Regular Expressions (PCRE) as used by Ruby’s Regexp class:
http://www.bitcetera.com/en/techblog/2008/04/01/regex-in-a-nutshell/

