Class LookAroundAssertion

All Implemented Interfaces:
AbstractState<Term,ASTTransition>, RegexASTVisitorIterable, JsonConvertible
Direct Known Subclasses:
LookAheadAssertion, LookBehindAssertion

public abstract class LookAroundAssertion extends RegexASTSubtreeRootNode
An assertion that succeeds depending on whether or not text surrounding the current position matches a given regular expression.

See its two subclasses, LookAheadAssertion and LookBehindAssertion.

  • Method Details

    • isNegated

      public boolean isNegated()
      Indicates whether this is a negative lookaround assertion (written as (?!...) (?<!...)) or a positive one (written as (?=...) or (?<=)).

      Positive lookaround assertions match if and only if the text around the current position matches the contents of the assertion. Negative lookaround assertions match if and only if the text around the current position does not match the contents of the assertion.

    • setNegated

      public void setNegated(boolean negated)
    • startsWithCharClass

      public boolean startsWithCharClass()
    • endsWithCharClass

      public boolean endsWithCharClass()
    • isLiteral

      public boolean isLiteral()
      Checks if the contents of this assertion (RegexASTSubtreeRootNode.getGroup()) are in "literal" form. This means that there is only a single alternative which is composed of a sequence of CharacterClass nodes.
    • getLiteralLength

      public int getLiteralLength()
      Returns the length of the words that can be matched by the body of this lookbehind assertion.

      Because we restrict the regular expressions used in lookbehind assertions to "literal" regular expressions, all strings that match the body of the assertion are guaranteed to be of the same length. This is critical to how lookbehind is implemented, because it tells us how much do we have to rewind when matching a regular expression with lookbehind assertions.

    • isSingleCCNonCapturingLiteral

      public boolean isSingleCCNonCapturingLiteral()
      Returns true iff this is a literal of size 1, without any capturing groups.