Facilitando as expressões regulares

JavaVerbalExpressions é uma biblioteca Java que ajuda a construir expressões regulares difíceis.

VerbalExpression testRegex = new VerbalExpression ()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
.anythingBut(" ")
.endOfLine();

// Create an example URL
String url = "https://www.google.com";

// Use VerbalExpression's testExact() method to test if the entire string matches
// the regex
testRegex
.testExact(url); //True

testRegex
.toString(); // Ouputs the regex used:
// ^(http)(s)?(://)(www.)?([^ ]*)$

VerbalExpression testRegex = new VerbalExpression ()
.startOfLine()
.then("abc")
.or("def");

String testString = "defzzz";

//Use VerbalExpression's test() method to test if parts if the string match the regex
testRegex
.test(testString); //true
testRegex
.testExact(testString); //false

Sim, as expressões regulares podem ser tão fáceis.

https://github.com/VerbalExpressions/JavaVerbalExpressions