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 s = "this is a good example with 234 songs";

        Pattern p = Pattern.compile("this is a (.*?) example with (\\d+) songs");
        Matcher m = p.matcher(s);
        if (m.matches()) {
            String kind = m.group(1);
            String nbr = m.group(2);

            System.out.println("kind: " + kind + " nbr: " + nbr);
        }
    }
}