get matches within string, using given regular expression
Parameters
match string :string
regex :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"
match "x: 123, y: 456" {/[0-9]+/}
match "this is a string" {/[0-9]+/}
copy
match.once "x: 123, y: 456" {/[0-9]+/}
copy
match.count "some words" {/\w+/}
copy
match.capture "abc" {/(.)/}
match.capture "x: 123, y: 456 - z: 789, w: 012"
{/\w: (\d+), \w: (\d+)/}
copy
inspect match.capture.named "x: 123, y: 456 - z: 789, w: 012"
{/\w: (?\d+), \w: (?\d+)/}
copy
match.bounds "hELlo wORLd" {/[A-Z]+/}
copy
match.in:0..2 "hello" {/l/}
Related