get matches within string, using given regular expression
Parameters
match string :string
regex :char :string :regex
Attributes
once | | get just the first match |
count | | just get number of matches |
capture | | get capture groups only |
named | | get named capture groups as a dictionary |
bounds | | get match bounds only |
in | :range | get matches within given range |
full | | get results as an array of match results |
Returns
- :integer
- :dictionary
- :block
Examples
copy
match "hello" "hello" ; => ["hello"]
match "x: 123, y: 456" {/[0-9]+/} ; => ["123" "456"]
match "this is a string" {/[0-9]+/} ; => []
copy
match.once "x: 123, y: 456" {/[0-9]+/} ; => ["123"]
copy
match.count "some words" {/\w+/} ; => 2
copy
match.capture "abc" {/(.)/} ; => ["a" "b" "c"]
match.capture "x: 123, y: 456 - z: 789, w: 012"
{/\w: (\d+), \w: (\d+)/}
; => [["123" "456"] ["789" "012"]]
copy
inspect match.capture.named "x: 123, y: 456 - z: 789, w: 012"
{/\w: (?\d+), \w: (?\d+)/}
;[ :block
; [ :dictionary
; numA : 123 :string
; numB : 456 :string
; ]
; [ :dictionary
; numA : 789 :string
; numB : 012 :string
; ]
;]
copy
match.bounds "hELlo wORLd" {/[A-Z]+/}
; => [1..2 7..9]
copy
match.in:0..2 "hello" {/l/} ; => ["l"]
Related