Method: StringUtils#split3
- Defined in:
- lib/buzzcore/string_utils.rb
#split3(aPattern, aOccurence = 0) ⇒ Object
given (‘abcdefg’,‘c.*?e’) returns [‘ab’,‘cde’,‘fg’] so you can manipulate the head, match and tail seperately, and potentially rejoin
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/buzzcore/string_utils.rb', line 23 def split3(aPattern,aOccurence=0) aString = self matches = aString.scan_md(aPattern) match = matches[aOccurence] parts = (match ? [match.pre_match,match.to_s,match.post_match] : [aString,nil,'']) if !block_given? # return head,match,tail parts else # return string parts[1] = yield *parts if match parts.join end end |