API Reference › Regex › Regex.group
method

Regex.group

Regex.group(match, n) -> string

Returns the substring captured by group n of match — group 0 is the whole match, 1 the first parenthesized group, and so on. Returns an empty string if the group did not participate in the match.

Parameters

matcha Match from Regex.find / Regex.exec / Regex.next
nthe group number (0 = whole match)

Example

program Demo {
  entry {
    let m = Regex.find("key=value", "(\\w+)=(\\w+)")
    print(Regex.group(m, 2))
  }
}
← All symbols