Function rexec

  • Easily perform regex 'exec' on a string. An iterable is returned which steps through the exec process and yields all the details you might need.

    Parameters

    • regex: RegExp

      The regular expression object

    • string: string

      The string to perform the operation on

    Returns Generator<RexecYield>

    A generator that yields an object for each match.

    Throws

    If the provided regex is not a RegExp instance.

    Example

    const regex = /(?<g1>a)/g
    const str = 'Anthony wants a girlfriend.'
    console.log([...rexec(regex, str)])
    // [
    // {
    // index: 9,
    // lastIndex: 10,
    // groups: { g1: 'a' },
    // match: 'a',
    // },
    // {
    // index: 14,
    // lastIndex: 15,
    // groups: { g1: 'a' },
    // match: 'a',
    // },
    // ]

Generated using TypeDoc