class ICU::Regex::Match

Overview

Represents a single match result, including captured groups.

Defined in:

icu/regex.cr

Instance Method Summary

Instance Method Detail

def begin(n : Int32 = 0) : Int32 #

Returns the byte offset in the input text where the given group begins.


[View source]
def end(n : Int32 = 0) : Int32 #

Returns the byte offset in the input text just past where the given group ends.


[View source]
def group(n : Int32) : String | Nil #

Returns the text of the given capture group (0 = whole match).

Returns nil if the group did not participate in the match.

m = ICU::Regex.new("(\\w+)").match("hello")
m.group(0) # => "hello"
m.group(1) # => "hello"

[View source]
def group(name : String) : String | Nil #

Returns the text of the given named capture group.

Returns nil if the group did not participate in the match.

m = ICU::Regex.new("(?<word>\\w+)").match("hello")
m.group("word") # => "hello"

[View source]
def group_count : Int32 #

Returns the number of capture groups in the pattern.


[View source]
def range(n : Int32 = 0) : Range(Int32, Int32) #

Returns the match range of the given group as a Range.

m = ICU::Regex.new("\\w+").match("hello world")
m.range # => 0...5

[View source]
def to_s : String #

Returns the whole match text (group 0).


[View source]