Class Anchors

java.lang.Object
dev.yasint.regexsynth.ast.Anchors

public final class Anchors
extends java.lang.Object
  • Constructor Summary

    Constructors 
    Constructor Description
    Anchors()  
  • Method Summary

    Modifier and Type Method Description
    static Expression endOfLine​(boolean crlf)
    Inserts a end of line character at position.
    static Expression endOfText()
    Inserts a end of text/string assertion at the position.
    static Expression exactLineMatch​(Expression... expressions)
    Appends a start of line and end of line anchors to an expression.
    static Expression exactWordBoundary​(Expression... expressions)
    Wraps an expression with '\b' at start and end.
    static Expression nonWordBoundary()
    Inserts a negated word boundary at position.
    static Expression startOfLine()
    Inserts a start of line character at position.
    static Expression startOfText()
    Inserts a start of text/string assertion at the position.
    static Expression wordBoundary()
    Inserts a word boundary at position.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • wordBoundary

      public static Expression wordBoundary()
      Inserts a word boundary at position. There are different positions that qualify as a word boundary.

      First, it can be used before the first character in the string, if the first character is a word character. Second, after the last character in the string, if the last character is a word character. Third, between two characters in the string, where one is a word character and the other is not a word character.

      Returns:
      boundary expression \b
    • nonWordBoundary

      public static Expression nonWordBoundary()
      Inserts a negated word boundary at position. \B matches at any position between two word characters as well as at any position between two non-word characters.
      Returns:
      non-boundary expression \B
    • startOfLine

      public static Expression startOfLine()
      Inserts a start of line character at position. When we use an anchor in the search expression, the engine does not advance through the string or consume characters; it looks for a match in the specified position only. i.e. ^http: matches "http:" only when it occurs at the beginning of a line; else the engine will return immediately.
      Returns:
      expression start of line ^
    • endOfLine

      public static Expression endOfLine​(boolean crlf)
      Inserts a end of line character at position. Use `$` with the multiline option, the match can also occur at the end of a line. `$` matches `\n` but does not match `\r\n`
      Parameters:
      crlf - \r\n combination, appended \r before \n if true.
      Returns:
      expression
    • startOfText

      public static Expression startOfText()
      Inserts a start of text/string assertion at the position. This only ever matches at the start of the string and never matches at line breaks. However, \A is different from ^. Because ^ and $ match up until a newline character.
      Returns:
      expression \A absolute start
    • endOfText

      public static Expression endOfText()
      Inserts a end of text/string assertion at the position.
      Returns:
      expression \z absolute end
    • exactLineMatch

      public static Expression exactLineMatch​(Expression... expressions)
      Appends a start of line and end of line anchors to an expression. ^ some-other-expressions $
      Parameters:
      expressions - in-between expressions
      Returns:
      wrapped expression ^...$
    • exactWordBoundary

      public static Expression exactWordBoundary​(Expression... expressions)
      Wraps an expression with '\b' at start and end. If an expression is wrapped around this, it ensures that the regex does not match part of a longer word/expression.
      Parameters:
      expressions - to wrap.
      Returns:
      new wrapped expression \b some-other-expression(s) \b