Class RegexObject

All Implemented Interfaces:
com.oracle.truffle.api.interop.TruffleObject

public final class RegexObject extends AbstractConstantKeysObject
RegexObject represents a compiled regular expression that can be used to match against input strings. It is the result of a call to RegexLanguage.parse(TruffleLanguage.ParsingRequest). It exposes the following properties:
  1. String pattern: the source of the compiled regular expression
  2. TruffleObject flags: the set of flags passed to the regular expression compiler. The type differs based on the flavor of regular expressions used:
  3. int groupCount: number of capture groups present in the regular expression, including group 0.
  4. RegexObject.RegexObjectExecMethod exec: an executable method that matches the compiled regular expression against a string. The method has two signatures:
    1. exec(TruffleString,int)(
    2. exec(TruffleString,int,int,int,int)(
      Their respective parameters are:
    1. TruffleString input: the string to search in. Its encoding must match the encoding selected via RegexOptions.
    2. Number fromIndex: the position to start searching from, i.e. the minimum starting index of capture group 0. Look-behind assertions are allowed to move past this index up to regionFrom. If fromIndex is greater than Integer.MAX_VALUE, this method will immediately return NO_MATCH.
    3. Number toIndex: the position to stop searching at, i.e. the maximum end index of capture group 0. Look-ahead assertions are allowed to move past this index up to regionTo. This parameter is not yet supported, but was added for future API compatibility. For now, this parameter must be equal to regionTo. Defaults to the input string's length.
    4. Number regionFrom: Hard string starting boundary. TRegex will not read any character preceding this index, and treat it as the string's start in respect to position assertions (^ and \A will match this index). Defaults to 0. Using regionFrom and regionTo, the caller can effectively restrict the search to a substring of input.
    5. Number regionTo: Hard string end boundary. TRegex will not read any character past this index, and treat it as the string's end in respect to position assertions ($, \Z and \z will match this index). Defaults to the input string's length. Using regionFrom and regionTo, the caller can effectively restrict the search to a substring of input.
    All index arguments will be converted to int, since a TruffleString can not be longer than Integer.MAX_VALUE.
    The return value is a RegexResult. The contents of the exec can be compiled lazily and so its first invocation might involve a longer delay as the regular expression is compiled on the fly.
  5. TruffleObject groups: a Truffle object that has a member for every named capture group. The value of the member depends on the flavor of regular expressions. In flavors where all capture groups must have a unique name, the value of the member is a single integer, the index of the group that bears the member's name. In flavors where it is possible to have multiple groups of the same name (as in Ruby), the value of the member has array elements that give the indices of the groups with the member's name.
  6. boolean isBacktracking: whether or not matching with this regular expression will use backtracking when matching, which could result in an exponential runtime in the worst case scenario