match

get matches within string, using given regular expression


Parameters

match string :string
      regex :char :string :regex

Attributes

onceget just the first match
countjust get number of matches
captureget capture groups only
namedget named capture groups as a dictionary
boundsget match bounds only
in:rangeget matches within given range
fullget 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