Class: Regexp
Instance Method Summary collapse
-
#each_match(target) ⇒ Object
Searches the target for all occurrances of this Regex.
Instance Method Details
#each_match(target) ⇒ Object
Searches the target for all occurrances of this Regex. If a block is given, yields each match found. Returns an array of all matches found.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/sc-core-ext/regexp.rb', line 4 def each_match(target) matches = [] offset = 0 while offset < target.length && !(match = match(target[offset..-1])).nil? offset += match.offset(0)[1] yield match if block_given? matches << match end matches end |