U:RDoc::AnyMethod[iI" scan:ETI"String#scan;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"QBoth forms iterate through str, matching the pattern (which may be a ;TI"PRegexp
or a String
). For each match, a result is ;TI"Ogenerated and either added to the result array or passed to the block. If ;TI"Lthe pattern contains no groups, each individual result consists of the ;TI"Lmatched string, $&
. If the pattern contains groups, each ;TI"Iindividual result is itself an array containing one entry per group.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [
I"a = "cruel world"
;TI"1a.scan(/\w+/) #=> ["cruel", "world"]
;TI"4a.scan(/.../) #=> ["cru", "el ", "wor"]
;TI":a.scan(/(...)/) #=> [["cru"], ["el "], ["wor"]]
;TI";a.scan(/(..)(..)/) #=> [["cr", "ue"], ["l ", "wo"]]
;T:@format0o;
; [I"And the block form:;T@o;; [ I",a.scan(/\w+/) {|w| print "<<#{w}>> " }
;TI"print "\n"
;TI"*a.scan(/(.)(.)/) {|x,y| print y, x }
;TI"print "\n"
;T;
0o;
; [I"produces:;T@o;; [I"<> <>
;TI"rceu lowlr;T;
0:
@fileI"
string.c;T:0@omit_headings_from_table_of_contents_below0I"istr.scan(pattern) -> array
str.scan(pattern) {|match, ...| block } -> str
;T0[ I" (p1);T@+FI"String;TcRDoc::NormalClassI"
scanf;T0