Pattern: compile('(\\w+)\\s(\\d+)') : Pattern « java.util.regex « Java by API






Pattern: compile('(\\w+)\\s(\\d+)')

import java.util.regex.*;

public class MainClass {
  public static void main(String[] args) {
    Pattern patt = Pattern.compile("(\\w+)\\s(\\d+)"); 
    Matcher matcher = patt.matcher("Bananas 123"); 
    matcher.lookingAt();
    System.out.println("Name: " + matcher.group(1)); 
    System.out.println("Number: " + matcher.group(2)); 
  }
}

           
       








Related examples in the same category

1.Pattern.CANON_EQ
2.Pattern.CASE_INSENSITIVE
3.Pattern: compile('d.*ian')
4.Pattern: compile('e.+?d')
5.Pattern: compile('[a-z]+')
6.Pattern: compile(String text)
7.Pattern: matcher(String text)
8.Pattern: split(String str)