method
match
![Wide documentation Importance_3](https://d2vfyqvduarcvs.cloudfront.net/images/importance_3.png?1349367920)
match(p1)
public
Register or
log in
to add new notes.
Oleg -
March 5, 2009
svoop -
February 10, 2009
![Default_avatar_30](https://www.gravatar.com/avatar/26dcc25613404cafb8a03d946ec3bcf6?default=http://apidock.com/images/default_avatar_30.png&size=30)
7 thanks
String#match will match single token only
>> s = “{{person}} ate {{thing}}”
> “{{person}} ate {{thing}}”
>> r = /{{(.*?)}}/
> {{}}
>> s.match®.captures
> [“person”]
Using String#scan pulls out all tokens you were searching for:
>> s.scan®.flatten
> [“person”, “thing”]
![Default_avatar_30](https://www.gravatar.com/avatar/2e2032cf85e31e19a6758b193782d686?default=http://apidock.com/images/default_avatar_30.png&size=30)
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/