Why
VerbalExpression.regex()
.startOfLine().then("http").maybe("s")
.then("://")
.maybe("www.").anythingBut(" ")
.endOfLine()
.build();
Instead of new VerbalExpression()
.startOfLine().then("http").maybe("s")
.then("://")
.maybe("www.").anythingBut(" ")
.endOfLine();java.lang.String works exactly this way. You're already used to the pattern.
Builders are used in Java* when you have an object which is invalid without passing in a bunch of parameters, but you don't want to have to remember the order of the parameters. But this is not one of these cases.
There is one drawback, however: you do have to compile the regex into a FSA at some point and it wouldn't be good to do that for every intermediate regex. So I assume that the compilation happens in the "build" step. They could have just called it "compile", though.
* named parameters in constructors seem a better alternative in every language that supports them, e.g. Kotlin
`REGEX.startOfLine().then("http")...`
Since the start object is immutable, there's no reason to create new ones. Here's an example of this pattern applied to HTTP (my project):
https://github.com/stickfigure/hattery
Avoiding repeated Pattern.compile() is a good point though.