Simply Regex

Simple API to build complex regex patterns.

License

License

GroupId

GroupId

com.itsallbinary
ArtifactId

ArtifactId

simply-regex
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Simply Regex
Simple API to build complex regex patterns.
Project URL

Project URL

http://itsallbinary.com/
Source Code Management

Source Code Management

https://github.com/itsallbinary/simply-regex

Download simply-regex

How to add to project

<!-- https://jarcasting.com/artifacts/com.itsallbinary/simply-regex/ -->
<dependency>
    <groupId>com.itsallbinary</groupId>
    <artifactId>simply-regex</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.itsallbinary/simply-regex/
implementation 'com.itsallbinary:simply-regex:1.1.0'
// https://jarcasting.com/artifacts/com.itsallbinary/simply-regex/
implementation ("com.itsallbinary:simply-regex:1.1.0")
'com.itsallbinary:simply-regex:jar:1.1.0'
<dependency org="com.itsallbinary" name="simply-regex" rev="1.1.0">
  <artifact name="simply-regex" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.itsallbinary', module='simply-regex', version='1.1.0')
)
libraryDependencies += "com.itsallbinary" % "simply-regex" % "1.1.0"
[com.itsallbinary/simply-regex "1.1.0"]

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.11.0

Project Modules

There are no modules declared in this project.

Project Simply Regex

Creator - Its All Binary

License - Apache 2.0

Releases/Dependencies - Maven Central Build Status codecov

Refer release page http://itsallbinary.com/project-simply-regex/simply-regex-releases/

User Guide - http://itsallbinary.com/project-simply-regex/simply-regex-user-guide/

Extension Library - https://github.com/itsallbinary/simply-regex-datatype

More Details - Refer to http://itsallbinary.com/project-simply-regex/ for more details

Simply Regex Quick Start

Basic Example:

This is the simplest regex example using simply regex.

// Basic Example
import com.itsallbinary.simplyregex.SimpleRegex;
 
String builtRegex = SimpleRegex.regex().startingWith().exactString("abc").build();
 
Pattern pattern = Pattern.compile(builtRegex);
 
boolean isMatch = pattern.matcher(testString).matches();

This will build regex as = ^abc Input: testString = “abc” Output: isMatch = true Input: testString = “def” Output: isMatch = false

Chaining multiple patterns

You can chain multiple patterns to create entire complex regex as shown in below example.

// Chaining example
import com.itsallbinary.simplyregex.SimpleRegex;
 
String builtRegex = SimpleRegex.regex().startingWith().exactString("abc")
                                       .then().oneOfTheCharacters('d', 'e', 'f')
                                       .build();
 
Pattern pattern = Pattern.compile(builtRegex);
 
boolean isMatch = pattern.matcher(testString).matches();

This will build regex as = ^abc[def] Input: testString = “abcd” Output: isMatch = true Input: testString = “abcg” Output: isMatch = false

Special wildcard character classes

Simply regex API provides easy readable methods for wild card character classes as shown in below example.

// Special wildcard example
import com.itsallbinary.simplyregex.SimpleRegex;
 
String builtRegex = SimpleRegex.regex().startingWith().anyDigitChar().build();
 
Pattern pattern = Pattern.compile(builtRegex);
 
boolean isMatch = pattern.matcher(testString).matches();

This will build regex as = ^\d Input: testString = “1” Output: isMatch = true Input: testString = “a” Output: isMatch = false

Easy & simple quantifiers

Simply regex API provides easy readable methods for quantifiers as shown below.

// Quantifier example
import com.itsallbinary.simplyregex.SimpleRegex;
 
String builtRegex = SimpleRegex.regex().anywhereInText().oneOrMoreOf('a').build();
 
Pattern pattern = Pattern.compile(builtRegex);
 
boolean isMatch = pattern.matcher(testString).matches();

This will build regex as = a+ Input: testString = “” Output: isMatch = false Input: testString = “a” Output: isMatch = true Input: testString = “aaa” Output: isMatch = true

Simple way to mix & match groups

Simply regex API provides easy & readable way to create groups & mix with other regex functions.

// Groups example
import com.itsallbinary.simplyregex.SimpleRegex;
 
String builtRegex = SimpleRegex.regex().anywhereInText()
		       .oneOrMoreOf(groupHaving().exactString("abc").then().anyDigitChar().build())
                       .build()
 
Pattern pattern = Pattern.compile(builtRegex);
 
boolean isMatch = pattern.matcher(testString).matches();

This will build regex as = (abc\d)+ Input: testString = “abc1abc2” Output: isMatch = true Input: testString = “abcz” Output: isMatch = false

Simple capture groups

Simple & fluent way to create capture groups.

// Capture Group Example
String builtRegex = SimpleRegex.regex().anywhereInText()
                      .exactString("My Name is ")
                      .then()
		      .group(
                          groupHaving().oneOrMoreOf(charThatIs().anyWordChar().build()
                       ).build())
                      .then()
                      .exactString(". ")
		      .build();
		
String testString = "My Name is John. My Name is Merry. My Name is Rock. ";
 
Matcher matcher = Pattern.compile(builtRegex).matcher(testString);
matcher.find();
assertEquals("John", matcher.group(1));
matcher.find();
assertEquals("Merry", matcher.group(1));
matcher.find();
assertEquals("Rock", matcher.group(1));
com.itsallbinary

Versions

Version
1.1.0
1.0.0
1.0.alpha.01