Creator - Its All Binary
License - Apache 2.0
Releases/Dependencies -
Refer release page http://itsallbinary.com/project-simply-regex/simply-regex-releases/
User Guide - http://itsallbinary.com/project-simply-regex/simply-regex-user-guide/
More Details - Refer to http://itsallbinary.com/project-simply-regex/ for more details
This is example of simple way of creating number regex.
// Basic Example
import com.itsallbinary.simplyregex.datatype.SimpleDataTypeRegex.*;
String ipRegex = regex().anywhereInText().def(number().between(0, 255).def())
.then().exactString(".")
.then() .def(number().between(0, 255).def())
.then().exactString(".")
.then().def(number().between(0, 255).def())
.then().exactString(".")
.then().def(number().between(0, 255).def()).build();
Pattern pattern = Pattern.compile(ipRegex);
boolean isMatch = pattern.matcher(input).matches();
This will build complex regex - ipRegex = ([0-9]|[1-9][0-9]|[1-1][0-9][0-9]|[2-2][0-4][0-9]|[2-2][5-5][0-5]|)\Q.\E([0-9]|[1-9][0-9]|[1-1][0-9][0-9]|[2-2][0-4][0-9]|[2-2][5-5][0-5]|)\Q.\E([0-9]|[1-9][0-9]|[1-1][0-9][0-9]|[2-2][0-4][0-9]|[2-2][5-5][0-5]|)\Q.\E([0-9]|[1-9][0-9]|[1-1][0-9][0-9]|[2-2][0-4][0-9]|[2-2][5-5][0-5]|)
Input: testString = “20.0.255.100” Output: isMatch = true Input: testString = “20.0.256.100” Output: isMatch = false
This is example of simple way of creating date regex using format accepted by SimpleDateFormat
// Basic Example
import com.itsallbinary.simplyregex.datatype.SimpleDataTypeRegex.*;
String regex = regex().anywhereInText().def(date().withDateFormat("MM/dd/yyyy").def()).build();
String input = "Today is 10/06/2018.";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
boolean isMatch = matcher.find();
String matchedDate = matcher.group();
assertEquals("Testing for regex = " + regex + " input =" + input, "10/06/2018", matchedDate);
This will build complex regex - regex = ((0{0,1}[1-9]|[1-1][0-2]|))\Q/\E((0{0,1}[1-9]|[1-2][0-9]|[3-3][0-1]|))\Q/\E([\d]{4})