public static class VerbalExpression.Builder extends Object
| Modifier and Type | Method and Description |
|---|---|
VerbalExpression.Builder |
add(String pValue)
Append literal expression
Everything added to the expression should go trough this method
(keep in mind when creating your own methods).
|
VerbalExpression.Builder |
add(VerbalExpression.Builder regex)
Append a regex from builder and wrap it with unnamed group (?: ...
|
VerbalExpression.Builder |
addModifier(char pModifier) |
VerbalExpression.Builder |
any(String value)
Shortcut to
anyOf(String) |
VerbalExpression.Builder |
anyOf(String pValue) |
VerbalExpression.Builder |
anything()
Add expression that matches anything (includes empty string)
|
VerbalExpression.Builder |
anythingBut(String pValue)
Add expression that matches anything, but not passed argument
|
VerbalExpression.Builder |
atLeast(int from)
Produce range count with only minimal number of occurrences
for example:
.find("w").atLeast(1) // produce (?:w){1,}
|
VerbalExpression.Builder |
br()
Shortcut for
lineBreak() |
VerbalExpression |
build() |
VerbalExpression.Builder |
capt()
Shortcut for
capture() |
VerbalExpression.Builder |
capture()
Adds capture - open brace to current position and closed to suffixes
|
VerbalExpression.Builder |
count(int count)
Add count of previous group
for example:
.find("w").count(3) // produce - (?:w){3}
|
VerbalExpression.Builder |
count(int from,
int to)
Produce range count
for example:
.find("w").count(1, 3) // produce (?:w){1,3}
|
VerbalExpression.Builder |
digit()
Add same as [0-9]
|
VerbalExpression.Builder |
endCapt()
Shortcut for
endCapture() |
VerbalExpression.Builder |
endCapture()
Close brace for previous capture and remove last closed brace from suffixes
Can be used to continue build regex after capture or to add multiply captures
|
VerbalExpression.Builder |
endGr()
Closes current unnamed and unmatching group
Shortcut for
endCapture()
Use it with group() for prettify code
Example:
regex().group().maybe("word").count(2).endGr() |
VerbalExpression.Builder |
endOfLine()
Mark the expression to end at the last character of the line
Same as
endOfLine(boolean) with true arg |
VerbalExpression.Builder |
endOfLine(boolean pEnable)
Enable or disable the expression to end at the last character of the line
|
VerbalExpression.Builder |
find(String value)
Add a string to the expression
Syntax sugar for
then(String) - use it in case:
regex().find("string") // when it goes first |
VerbalExpression.Builder |
group()
Same as
capture(), but don't save result
May be used to set count of duplicated captures, without creating a new saved capture
Example:
// Without group() - count(2) applies only to second capture
regex().group()
.capt().range("0", "1").endCapt().tab()
.capt().digit().count(5).endCapt()
.endGr().count(2); |
VerbalExpression.Builder |
lineBreak()
Add universal line break expression
|
VerbalExpression.Builder |
maybe(String pValue)
Add a string to the expression that might appear once (or not)
Example:
The following matches all strings that contain http:// or https://
VerbalExpression regex = regex()
.find("http")
.maybe("s")
.then("://")
.anythingBut(" ").build();
regex.test("http://") //true
regex.test("https://") //true
|
VerbalExpression.Builder |
maybe(VerbalExpression.Builder regex)
Add a regex to the expression that might appear once (or not)
Example:
The following matches all names that have a prefix or not.
|
VerbalExpression.Builder |
multiple(String pValue,
int... count)
Convenient method to show that string usage count is exact count, range count or simply one or more
Usage:
regex().multiply("abc") // Produce (?:abc)+
regex().multiply("abc", null) // Produce (?:abc)+
regex().multiply("abc", (int)from) // Produce (?:abc){from}
regex().multiply("abc", (int)from, (int)to) // Produce (?:abc){from, to}
regex().multiply("abc", (int)from, (int)to, (int)...) // Produce (?:abc)+
|
VerbalExpression.Builder |
nonDigit()
Add non-digit: [^0-9]
|
VerbalExpression.Builder |
nonSpace()
Add non-whitespace character: [^\s]
|
VerbalExpression.Builder |
nonWordChar()
Add non-word character: [^\w]
|
VerbalExpression.Builder |
oneOf(String... pValues)
Adds an alternative expression to be matched
based on an array of values
|
VerbalExpression.Builder |
oneOrMore()
Adds "+" char to regexp
Same effect as
atLeast(int) with "1" argument
Also, used by multiple(String, int...) when second argument is null, or have length more than 2 |
VerbalExpression.Builder |
or(String pValue)
Add a alternative expression to be matched
Issue #32
|
VerbalExpression.Builder |
range(String... pArgs)
Add expression to match a range (or multiply ranges)
Usage: .range(from, to [, from, to ...
|
VerbalExpression.Builder |
removeModifier(char pModifier) |
VerbalExpression.Builder |
searchOneLine(boolean pEnable) |
VerbalExpression.Builder |
something()
Add expression that matches something that might appear once (or more)
|
VerbalExpression.Builder |
somethingButNot(String pValue) |
VerbalExpression.Builder |
space()
Add whitespace character, same as [ \t\n\x0B\f\r]
|
VerbalExpression.Builder |
startOfLine()
Mark the expression to start at the beginning of the line
Same as
startOfLine(boolean) with true arg |
VerbalExpression.Builder |
startOfLine(boolean pEnable)
Enable or disable the expression to start at the beginning of the line
|
VerbalExpression.Builder |
tab()
Add expression to match a tab character (' ')
|
VerbalExpression.Builder |
then(String pValue)
Add a string to the expression
|
VerbalExpression.Builder |
withAnyCase()
Turn ON matching with ignoring case
Example:
// matches "a"
// matches "A"
regex().find("a").withAnyCase()
|
VerbalExpression.Builder |
withAnyCase(boolean pEnable) |
VerbalExpression.Builder |
word()
Add word, same as [a-zA-Z_0-9]+
|
VerbalExpression.Builder |
wordChar()
Add word character, same as [a-zA-Z_0-9]
|
VerbalExpression.Builder |
zeroOrMore()
Adds "*" char to regexp, means zero or more times repeated
Same effect as
atLeast(int) with "0" argument |
public VerbalExpression build()
public VerbalExpression.Builder add(String pValue)
pValue - - literal expression, not sanitizedpublic VerbalExpression.Builder add(VerbalExpression.Builder regex)
regex - - VerbalExpression.Builder, that not changedpublic VerbalExpression.Builder startOfLine(boolean pEnable)
pEnable - - enables or disables the line startingpublic VerbalExpression.Builder startOfLine()
startOfLine(boolean) with true argpublic VerbalExpression.Builder endOfLine(boolean pEnable)
pEnable - - enables or disables the line endingpublic VerbalExpression.Builder endOfLine()
endOfLine(boolean) with true argpublic VerbalExpression.Builder then(String pValue)
pValue - - the string to be looked for (sanitized)public VerbalExpression.Builder find(String value)
then(String) - use it in case:
regex().find("string") // when it goes firstvalue - - the string to be looked for (sanitized)public VerbalExpression.Builder maybe(String pValue)
pValue - - the string to be looked forpublic VerbalExpression.Builder maybe(VerbalExpression.Builder regex)
regex - - the string to be looked forpublic VerbalExpression.Builder anything()
public VerbalExpression.Builder anythingBut(String pValue)
pValue - - the string not to matchpublic VerbalExpression.Builder something()
public VerbalExpression.Builder somethingButNot(String pValue)
public VerbalExpression.Builder lineBreak()
public VerbalExpression.Builder br()
lineBreak()public VerbalExpression.Builder tab()
public VerbalExpression.Builder word()
public VerbalExpression.Builder wordChar()
public VerbalExpression.Builder nonWordChar()
public VerbalExpression.Builder nonDigit()
public VerbalExpression.Builder digit()
public VerbalExpression.Builder space()
public VerbalExpression.Builder nonSpace()
public VerbalExpression.Builder anyOf(String pValue)
public VerbalExpression.Builder any(String value)
anyOf(String)value - - CharSequence every char from can be matchedpublic VerbalExpression.Builder range(String... pArgs)
pArgs - - pairs for rangepublic VerbalExpression.Builder addModifier(char pModifier)
public VerbalExpression.Builder removeModifier(char pModifier)
public VerbalExpression.Builder withAnyCase(boolean pEnable)
public VerbalExpression.Builder withAnyCase()
public VerbalExpression.Builder searchOneLine(boolean pEnable)
public VerbalExpression.Builder multiple(String pValue, int... count)
pValue - - the string to be looked forcount - - (optional) if passed one or two numbers, it used to show count or range countoneOrMore(),
then(String),
zeroOrMore()public VerbalExpression.Builder oneOrMore()
atLeast(int) with "1" argument
Also, used by multiple(String, int...) when second argument is null, or have length more than 2public VerbalExpression.Builder zeroOrMore()
atLeast(int) with "0" argumentpublic VerbalExpression.Builder count(int count)
count - - number of occurrences of previous group in expressionpublic VerbalExpression.Builder count(int from, int to)
from - - minimal number of occurrencesto - - max number of occurrencescount(int)public VerbalExpression.Builder atLeast(int from)
from - - minimal number of occurrencescount(int),
oneOrMore(),
zeroOrMore()public VerbalExpression.Builder or(String pValue)
pValue - - the string to be looked forpublic VerbalExpression.Builder oneOf(String... pValues)
pValues - - the strings to be looked forpublic VerbalExpression.Builder capture()
public VerbalExpression.Builder capt()
capture()public VerbalExpression.Builder group()
capture(), but don't save result
May be used to set count of duplicated captures, without creating a new saved capture
Example:
// Without group() - count(2) applies only to second capture
regex().group()
.capt().range("0", "1").endCapt().tab()
.capt().digit().count(5).endCapt()
.endGr().count(2);public VerbalExpression.Builder endCapture()
public VerbalExpression.Builder endCapt()
endCapture()public VerbalExpression.Builder endGr()
endCapture()
Use it with group() for prettify code
Example:
regex().group().maybe("word").count(2).endGr()Copyright © 2017. All rights reserved.