~~ multimethod
Methods
- ~~(haystack:Str, needle:Str, collect_unmatched:Bool=false) Source: stdlib.ngs:3527
Find all non-overlapping matches of a substring in a string. Returns
if collect_unmatched - Arr with each element being MatchY or Str, if not collect_unmatched - Arr of MatchYExample
["key=value", "key2=value2"].map(F(kv) { m = kv ~ "=" [m.before, m.after] }).Hash() # {'key': 'value', 'key2': 'value2'}
- ~~(s:Str, r:RegExp, collect_unmatched:Bool=false) Source: stdlib.ngs:5444
Find all non-overlapping matches of regular expression in a string. Returns
if collect_unmatched - Arr with each element being MatchY or Str, if not collect_unmatched - Arr of MatchYExample
("x10ab20c30y" ~~ /[0-9]+/).whole.map(Int).sum() # 60 arr = (~~)("x10ab20c30y", /[0-9]+/, true) arr .= map(F(elt) if elt is MatchY "[${elt.whole}]" else elt) arr.join("") # "x[10]ab[20]c[30]y"