I’m trying to validate regex in Ballerina using library samjs/jregex from https://central.ballerina.io/samjs/jregex I’m trying to get this executed:
import ballerina/io;
import samjs/jregex;
public function main() {
//io:println(Commons:isValidDateTime("dupa"));
jregex:Pattern p = jregex:compile(regex = ".r");
jregex:Matcher m = p.matcher(input = "br");
var b = m.matches();
io:println(b);
}
I have run command ballerina pull samjs/jregex
My Ballerina.toml is:
[project]
org-name= "organization"
version= "0.1.0"
[platform]
target= "java8"
[[platform.libraries]]
artifactId = "mssql-jdbc"
version = "8.2.0"
path = "./mssql-jdbc-8.2.0.jre8.jar"
[dependencies]
However this is not working, because I’m getting error:
error: module not found: ballerinax/java:*_java8 or ballerinax/java:*_anyerror: samjs/jregex:0.2.0::/src/jregex/matcher.bal:1:1: cannot resolve module 'ballerinax/java'
error: module not found: ballerinax/java:*_java8 or ballerinax/java:*_any
error: samjs/jregex:0.2.0::/src/jregex/pattern.bal:1:1: cannot resolve module 'ballerinax/java'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:85:29: undefined module 'java'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:85:29: undefined function 'fromString'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:128:69: undefined module 'java'
error: samjs/jregex:0.2.0::/src/jregex/matcher.bal:128:69: undefined annotation 'Method'
it seems that import of jregex requires ballerinax, however I cannot import to code anything that is not directly used (Ballerina does not allow for "empty" imports).
Does anybody knows how to import this regex library to make it working in application?