Created
August 27, 2017 13:08
-
-
Save rmxsantiago/b6648a4657f25a98d593ccf9177badac to your computer and use it in GitHub Desktop.
Regex which return content from each group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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