Skip to content

sameerajayasoma/jregex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Regex library for Ballerina

The samjs/jregx Ballerina module provides a set of utilities to work with regular expressions. This API has a close resemblance to Java Pattern/Matcher regex API. This is a mirror of the Java API for the most part. Here are a few sample usages.

First, use ballerina pull samjs/jregex to pull the latest version of the module from Ballerina central to your home repository.

import samjs/jregex;
import ballerina/io;

public function main() {
    jregex:Pattern p = jregex:compile(regex = ".r");
    jregex:Matcher m = p.matcher(input = "br");
    var b = m.matches();
    io:println(b);
}
import samjs/jregex;
import ballerina/io;

public function main() {
    var b = jregex:matches(regex = ".r", input = "br");
    io:println(b);
}
import samjs/jregex;
import ballerina/io;

public function main() {
    string input = "Jack and Jill went up the hill. To fetch a pail of water. " + 
            "Jack fell down and broke his crown, and Jill came tumbling after.";
    var p = jregex:compile(regex = "Jack");
    var m = p.matcher(input);
    while m.find() {
        var output = string `Group: ${m.findGroup()}, start: ${m.startIndex()}, end: ${m.endIndex()}`;
        io:println(output);
    }
}

About

A regex library for Ballerina

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published