# Io Reference

Parsers / Regex / RegexMatch

|  | Contains the result of a regular expression match operation. It acts as a read-only list of captured strings. The first item is the entire matched string. Each item after that is a captured sub pattern (anything inbetween parenthesis in the pattern).
    Io> match := "37signals" findRegex("([0-9]+)([a-z]+)(!!)?")
    ==> RegexMatch: "37signals"

    # Item 0 is the entire matched string:
    Io> match at(0)
    ==> 37signals

    # Item 1 is the first capture ("[0-9]+"):
    Io> match at(1)
    ==> 37

    # Item 2 is the second capture ("[a-z]+"):
    Io> match at(2)
    ==> signals

    # The third sub pattern wasn't part of the match, so item 3 is nil:
    Io> match at(3)
    ==> nil

    # You can access captures by name, if you name them:
    Io> match := "37signals" findRegex("(?[0-9]+)(?[a-z]+)(!!)?")
    ==> RegexMatch: "37signals"
    Io> match at("number")
    ==> 37
    Io> match at("word")
    ==> signals
|  | asString Returns a string containing a textual representation of the receiver. at(indexOrName) Returns the capture with the given index or name. `at(0)` is the entire match. captures Returns a list of captured strings. The first element is the whole match. end Returns the index into the subject at which the match ends. endOf(indexOrName) Returns the index into the subject at which the capture with the given index or name ends. expandTo(templateString) Returns templateString with capture placeholders replaced with what they represent. `$0` is replaced with the whole match, `$1` is replaced with the first sub capture, etc. `${name}` is replaced with the capture of that name. foreach([index], capture, message) Loops through the captures, assigns each capture to capture, and evaluates message. Returns a list with the result of each evaluation. indexOf(name) Returns the index of the capture with the given name. map([index], capture, message) Like `foreach`, but the result of each evaluation of message is returned in a list. nameOf(index) Returns the name of the capture with the given index. names Returns a list of the name of each named capture. If there are no named captures, the list will be empty. postfix Returns a slice of the subject string that contains all text after this match. Equivalent to:
    	match subject slice(match end)
prefix Returns a slice of the subject string that contains all text before this match. Equivalent to:
    	match subject slice(0, match start)
range Returns the range of the match in the subject. rangeOf(indexOrName) Returns the range of the capture with the given index or name. ranges Returns a list containing the range of each capture. regex Returns the Regex that was used to find this match. select([index], capture, message) Like `foreach`, but the values for which the result of evaluating message are non-nil are returned in a list. size Returns the number of captures. sizeInChars Returns the length of the match, in characters. slice(startIndex, [endIndex]) Returns a new list containing the subset of the receiver from the startIndex to the endIndex. The endIndex argument is optional. If not given, it is assumed to be the end of the capture list. start Returns the index into the subject at which the match starts. startOf(indexOrName) Returns the index into the subject at which the capture with the given index or name starts. string Returns the matched string. subject Returns the string that this match was found in.