List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:RegExpr6.java
public static void main(String args[]) { Pattern pat = Pattern.compile("e.+?d"); Matcher mat = pat.matcher("extend cup end table"); while (mat.find()) System.out.println("Match: " + mat.group()); }
From source file:Main.java
public static void main(String args[]) throws Exception { String regex = "(?<=http://)\\S+"; Pattern pattern = Pattern.compile(regex); String candidate = "http://www.a.com."; Matcher matcher = pattern.matcher(candidate); while (matcher.find()) { String msg = ":" + matcher.group() + ":"; System.out.println(msg);/*from w w w. j a va2s. 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(); matcher.appendReplacement(sb, replacement); String msg = sb.toString();// w w w.j a va2 s . co m System.out.println(msg); }
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("B(on)d"); String candidateString = "My name is Bond. James Bond."; String matchHelper[] = { " ^", " ^", " ^", " ^" }; Matcher matcher = p.matcher(candidateString); matcher.find(); // find the end point of the first sub group (ond) int nextIndex = matcher.end(1); System.out.println(candidateString); System.out.println(matchHelper[1] + nextIndex); }
From source file:Main.java
public static void main(String[] args) { Pattern pattern = Pattern.compile("<Mark([^>]*)>"); String myString = "this is a test <Mark this is a test> " + "<i>a</i> <Mark t> <b>x+y</b> <Mark 123>"; Matcher matcher = pattern.matcher(myString); while (matcher.find()) { System.out.println(matcher.group(1)); }/*from w ww . j a va2 s. c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://www.java.com/"); URLConnection urlConnection = url.openConnection(); DataInputStream dis = new DataInputStream(urlConnection.getInputStream()); String html = "", tmp = ""; while ((tmp = dis.readUTF()) != null) { html += " " + tmp; }/* w w w . j a v a2s . com*/ dis.close(); html = html.replaceAll("\\s+", " "); Pattern p = Pattern.compile("<title>(.*?)</title>"); Matcher m = p.matcher(html); while (m.find() == true) { System.out.println(m.group(1)); } }
From source file:GreedyExample.java
public static void main(String args[]) { String regex = "(\\w+)(\\d\\d)(\\w+)"; Pattern pattern = Pattern.compile(regex); String candidate = "X99SuperJava"; 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
License:asdf
public static void main(String args[]) { String regex = "\\w+"; Pattern pattern = Pattern.compile(regex); String candidate = "asdf Java2s.com"; Matcher matcher = pattern.matcher(candidate); if (matcher.find()) { System.out.println("GROUP 0:" + matcher.group(0)); }/* w w w . j a va 2 s .co m*/ }
From source file:MatcherFindExample.java
public static void main(String args[]) { Pattern p = Pattern.compile("Java"); String candidateString = "I love Java2s. Java2s is about Java."; Matcher matcher = p.matcher(candidateString); while (matcher.find()) { System.out.println(matcher.group()); }/*from www .j a v a 2 s . com*/ }
From source file:MatcherAppendReplacementGroupExample.java
public static void main(String args[]) { Pattern p = Pattern.compile("(James) (Bond)"); StringBuffer sb = new StringBuffer(); String candidateString = "My name is Bond. James Bond."; String replacement = "$1 Waldo $2"; Matcher matcher = p.matcher(candidateString); matcher.find(); matcher.appendReplacement(sb, replacement); String msg = sb.toString();//from ww w .ja va2 s .co m System.out.println(msg); }