List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:SimpleGroupExample.java
public static void main(String args[]) { Pattern p = Pattern.compile("\\w\\d"); String candidate = "J2 is my favorite"; Matcher matcher = p.matcher(candidate); if (matcher.find()) { String tmp = matcher.group(0); System.out.println(tmp);/* ww w .j av a 2s. c om*/ } }
From source file:Main.java
License:asdf
public static void main(String args[]) { String regex = "(\\w+)(\\d\\d)(\\w+)"; Pattern pattern = Pattern.compile(regex); String candidate = "X99 asdf 44"; Matcher matcher = pattern.matcher(candidate); matcher.find(); System.out.println(matcher.group(1)); System.out.println(matcher.group(2)); System.out.println(matcher.group(3)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Pattern p = Pattern.compile("t(est)"); String candidateString = "This is a test. This is a test."; Matcher matcher = p.matcher(candidateString); matcher.find(); String group_0 = matcher.group(0); String group_1 = matcher.group(1); System.out.println("Group 0 " + group_0); System.out.println("Group 1 " + group_1); }
From source file:RegExpr7.java
public static void main(String args[]) { Pattern pat = Pattern.compile("[a-z]+"); Matcher mat = pat.matcher("this is a test."); while (mat.find()) System.out.println("Match: " + mat.group()); }
From source file:Main.java
public static void main(String args[]) { String candidateString = "This is a test. This is another test."; Pattern p = Pattern.compile("test"); Matcher matcher = p.matcher(candidateString); matcher.find(); int endIndex = matcher.end(); System.out.println(candidateString); System.out.println(endIndex); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("Java"); String candidateString = "Java Java Java."; Matcher matcher = p.matcher(candidateString); while (matcher.find()) { System.out.println(matcher.group()); }//from www .j a v a 2 s. c o m }
From source file:MainClass.java
public static void main(String args[]) { Pattern pat = Pattern.compile("X+"); Matcher mat = pat.matcher("X XX XXX"); while (mat.find()) System.out.println("Match: " + mat.group()); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("t(est)"); String candidateString = "This is a test. This is another test"; Matcher matcher = p.matcher(candidateString); matcher.find(); int startIndex = matcher.start(0); System.out.println(candidateString); System.out.println(startIndex); }
From source file:MainClass.java
public static void main(String args[]) { String output = ""; Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("01234"); while (m1.find()) { System.out.println("\t\t" + m1.group()); }/*from w w w. j av a2 s. c o m*/ m1.reset("56789"); System.out.println("After resetting the Matcher"); while (m1.find()) { System.out.println("\t\t" + m1.group()); } }
From source file:RegExpr3.java
public static void main(String args[]) { Pattern pat = Pattern.compile("test"); Matcher mat = pat.matcher("test 1 2 3 test"); while (mat.find()) { System.out.println("test found at index " + mat.start()); }/*from ww w.j a v a 2s . c o m*/ }