Function match

  • Include another readable RegExp token in the current expression. This is useful for extracting and re-using common expressions.

    Parameters

    Returns RegExpToken

    Example

    const number = oneOrMore.digit;
    const coordinates = match(number).exactly`,`.match(number);

    This is equivalent to:

    const coordinates = oneOrMore.digit.exactly`,`.oneOrMore.digit;
    

    match can also accept multiple tokens and chain them together, which can be useful for code formatting.

    Example

    const filename = match(
    oneOrMore.word,
    exactly`_`,
    oneOrMore.digit,
    exactly`.txt`
    );

    This is equivalent to:

    const filename = oneOrMore.word.exactly`_`.oneOrMore.digit.exactly`.txt`;
    

Generated using TypeDoc