Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        String test = "this is your value : 100 . " + "And this is your account number : 219";
        String valueExpression = "\\svalue\\s:([^.]+)";
        String accExpresion = "\\saccount\\snumber\\s:([^$]+)";
        System.out.println("Value:" + runSubRegex(valueExpression, test));
        System.out.println("Account:" + runSubRegex(accExpresion, test));

    }

    private static String runSubRegex(String regex, String tag) {
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(tag);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }
}