Skip to content
/ Regex Public

A Java library to create and use regular expressions.

License

Notifications You must be signed in to change notification settings

xmlet/Regex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

Regex

This library is a Java library which uses a Java DSL, RegexApi, to create regular expressions and use the Java Pattern class to perform matches with the generated regular expression. The project itself is very simple, it implements a concrete implementation for the correct usage of the RegexApi to achieve this concrete objective. This project supports the whole syntax supported by the Java 8 Pattern Class. The objective of this project is to make regular expressions easier to use for people who aren't used to work with them, providing a fluent and intuitive way to define regular expressions.

Installation

First, in order to include it to your Maven project, simply add this dependency:

<dependency>
    <groupId>com.github.xmlet</groupId>
    <artifactId>regex</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

The regular expression is composed by multiple operations. Each one of the operations supported by Java is depicted in the tests of this project. Each test is properly documented with explanations regarding each method, providing a better understanding of the functionalities provided by this library. Let's take a look at one of the tests, testAtBeginningRegex on AnchorTests:
public class AnchorTest {
    public void testAtBeginningRegex(){
        String toMatch = "901-333-";
        Regex regex = new Regex(expr -> 
                expr.matchRegex().atBeginning().anyDigit().matchPreviousNTimes().attrN(3));
        List<String> result = regex.match(toMatch);

        Assert.assertEquals(1, result.size());
        Assert.assertEquals("901", result.get(0));
    }
}
In this example we define a regular expression with:

new Regex(expr -> expr.matchRegex().atBeginning().anyDigit().matchPreviousNTimes().attrN(3));

This regular expression will match any set of three digits placed on the beggining of a String. Defined in the regular expression syntax it would be:

^\d{3}

In this case we are using a the String 901-333-, therefore the expected result is 901. If you want to know more about the possibilities of this library explore the tests made available that best apply to the regular expressions that you want to generate.

About

A Java library to create and use regular expressions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages