Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/core_ext/string/pull_regex.rb
Instance Method Summary collapse
-
#pull_regex(regexp) ⇒ Object
Given ‘string’, find all matches of regular expression (removed from
string
) and return them as an array of strings.
Instance Method Details
#pull_regex(regexp) ⇒ Object
Given ‘string’, find all matches of regular expression (removed from string
) and return them as an array of strings.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/core_ext/string/pull_regex.rb', line 4 def pull_regex(regexp) found_values = [] until ((value = self[regexp]).nil?) vindex = index(value) self[ vindex .. (vindex + value.length) ] = "" found_values << value.match(regexp)[1] end return found_values end |