List of usage examples for java.util.regex Pattern compile
public static Pattern compile(String regex)
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("55"); Matcher m2 = p.matcher("fdshfdgdfh"); System.out.println(m1.pattern() == m2.pattern()); }
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();/* w ww . j ava 2s . c om*/ int startIndex = matcher.start(0); System.out.println(candidateString); System.out.println(startIndex); }
From source file:MainClass.java
public static void main(String[] args) { Pattern myRE = Pattern.compile("d.*ian"); Matcher matcher = myRE.matcher("danian devonian dan"); matcher.lookingAt();//from w w w. j a v a 2 s. c o m String result = matcher.group(0); System.out.println(result); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("test"); StringBuffer sb = new StringBuffer(); String candidateString = "This is a test."; String replacement = "Test"; Matcher matcher = p.matcher(candidateString); matcher.find();/* w ww. j a va 2 s. c o m*/ matcher.appendReplacement(sb, replacement); }
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("(i|I)ce"); String candidateString = "Ice. ice Ice Ice."; Matcher matcher = p.matcher(candidateString); String tmp = matcher.replaceAll("Java"); System.out.println(tmp);// ww w .ja va 2s . co m }
From source file:Main.java
public static void main(String args[]) { Pattern pat = Pattern.compile("\\b\\w+@XYZ\\.com\\b"); Matcher mat = pat.matcher("t@XYZ.com\n" + "a@XYZ.com\n" + "n@XYZ.com"); while (mat.find()) System.out.println("Match: " + mat.group()); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("\\w(\\d)"); String candidate = "w5 "; Matcher matcher = p.matcher(candidate); if (matcher.find()) { String tmp = matcher.group(0); System.out.println(tmp);/*from w ww. ja v a2 s.co m*/ tmp = matcher.group(1); System.out.println(tmp); } }
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); // Find group number 0 of the first find matcher.find();/*w w w . j a v a 2 s . c om*/ 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); System.out.println(candidateString); }
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("\\w\\d"); String candidate = "A6 is my favorite"; Matcher matcher = p.matcher(candidate); if (matcher.find()) { String tmp = matcher.group(0); System.out.println(tmp);/*ww w . j a v a 2s . c o m*/ } }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("(another) (test)"); StringBuffer sb = new StringBuffer(); String candidateString = "This is another test."; String replacement = "$1 AAA $2"; Matcher matcher = p.matcher(candidateString); matcher.find();/*from w w w. j a v a2 s . co m*/ matcher.appendReplacement(sb, replacement); String msg = sb.toString(); System.out.println(msg); }