Function getLengthRange

  • Returns how many characters the given element can consume at most and has to consume at least.

    Note that character classes are not parsed by this function and are assumed to be non-empty.

    Backreferences

    While isPotentiallyZeroLength generally assumes the worst-case for backreferences that references capturing group outside the given element, this function does not/cannot. The length range of a backreference only depends on the referenced capturing group and the relative positions of the backreference and the capturing group within the pattern. It does not depend on the given element.

    This is an important distinction because it means that isPotentiallyZeroLength(e) -> getLengthRange(e).min == 0 is guaranteed but getLengthRange(e).min == 0 -> isPotentiallyZeroLength(e) is only guaranteed if e does not contain backreferences.

    Parameters

    • element: Alternative | CapturingGroup | ClassRangesCharacterClass | UnicodeSetsCharacterClass | CharacterClassRange | ClassIntersection | ClassStringDisjunction | ClassSubtraction | ExpressionCharacterClass | Group | LookaheadAssertion | LookbehindAssertion | Quantifier | StringAlternative | Backreference | EdgeAssertion | WordBoundaryAssertion | Character | AnyCharacterSet | EscapeCharacterSet | CharacterUnicodePropertyCharacterSet | StringsUnicodePropertyCharacterSet | readonly Alternative[]
    • flags: ReadonlyFlags

    Returns LengthRange

    Throws

    if an empty array of alternatives is given.

    See