Package dev.yasint.regexsynth.ast
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 ExpressionendOfLine(boolean crlf)Inserts a end of line character at position.static ExpressionendOfText()Inserts a end of text/string assertion at the position.static ExpressionexactLineMatch(Expression... expressions)Appends a start of line and end of line anchors to an expression.static ExpressionexactWordBoundary(Expression... expressions)Wraps an expression with '\b' at start and end.static ExpressionnonWordBoundary()Inserts a negated word boundary at position.static ExpressionstartOfLine()Inserts a start of line character at position.static ExpressionstartOfText()Inserts a start of text/string assertion at the position.static ExpressionwordBoundary()Inserts a word boundary at position.
-
Constructor Details
-
Anchors
public Anchors()
-
-
Method Details
-
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
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
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
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
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
Inserts a end of text/string assertion at the position.- Returns:
- expression \z absolute end
-
exactLineMatch
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
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
-