Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regex which return content from each group
package com.company;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Main main = new Main();
String input = "[0-9]{1,13}";
String regex = "\\[.*]\\{([0-9]+),([0-9]+)}";
Pattern pattern = Pattern.compile(regex);
try {
Matcher matcher = pattern.matcher(input);
main.print(input, matcher);
}catch (Exception e){
e.printStackTrace();
}
}
public void print(String input, Matcher matcher){
System.out.println("Input: " + input);
System.out.println("Matches? " + matcher.matches());
System.out.println("Groups: " + matcher.groupCount());
System.out.println("Min: " + matcher.group(1));
System.out.println("Max: " + matcher.group(2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.