List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static void main(String args[]) { String regex = "(\\w++)(\\d\\d)(\\w+)"; Pattern pattern = Pattern.compile(regex); String candidate = "X99 test 55"; Matcher matcher = pattern.matcher(candidate); if (matcher.find()) { System.out.println("GROUP 0:" + matcher.group(0)); System.out.println("GROUP 1:" + matcher.group(1)); System.out.println("GROUP 2:" + matcher.group(2)); System.out.println("GROUP 3:" + matcher.group(3)); } else {/*from w ww .ja v a2s . c om*/ System.out.println("NO MATCHES"); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Pattern pattern = Pattern.compile("pattern"); FileInputStream input = new FileInputStream("file.txt"); FileChannel channel = input.getChannel(); ByteBuffer bbuf = channel.map(FileChannel.MapMode.READ_ONLY, 0, (int) channel.size()); CharBuffer cbuf = Charset.forName("8859_1").newDecoder().decode(bbuf); Matcher matcher = pattern.matcher(cbuf); while (matcher.find()) { String match = matcher.group(); System.out.println(match); }//w w w . j a v a 2 s . co m }
From source file:Main.java
public static void main(String args[]) { String regex = "(\\d+?)"; Pattern pattern = Pattern.compile(regex); String candidate = "1234"; Matcher matcher = pattern.matcher(candidate); while (matcher.find()) { System.out.println(matcher.group()); }//from w w w. j a va 2s .co m System.out.println("Done"); }
From source file:Main.java
public static void main(String[] arguments) throws Exception { String page = loadPage(arguments[0]); Pattern pattern = Pattern.compile("<a.+href=\"(.+?)\""); Matcher matcher = pattern.matcher(page); while (matcher.find()) { System.out.println(matcher.group(1)); }/*ww w. jav a 2 s. co m*/ }
From source file:MainClass.java
public static void main(String[] av) { String regEx = "[+|-]?(\\d+(\\.\\d*)?)|(\\.\\d+)"; String str = "a b c d e 1 2 3 4.5 "; Pattern pattern = Pattern.compile(regEx); Matcher m = pattern.matcher(str); while (m.find()) { for (int i = 0; i <= m.groupCount(); i++) { System.out.println("Group " + i + ": " + m.group(i)); // Group i substring }//from ww w .j a va 2 s . co m } }
From source file:PositiveLookBehindExample.java
public static void main(String args[]) throws Exception { String regex = "(?<=http://)\\S+"; Pattern pattern = Pattern.compile(regex); String candidate = "The Java2s website can be found at "; candidate += "http://www.java2s.com. There, "; candidate += "you can find information about some of "; candidate += "best example codes"; Matcher matcher = pattern.matcher(candidate); while (matcher.find()) { String msg = ":" + matcher.group() + ":"; System.out.println(msg);/* w ww . j a v a 2 s.co m*/ } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Pattern word = Pattern.compile("\\G\\w+"); Matcher mat = word.matcher("this is a test 999"); System.out.println(mat.find()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Pattern punct = Pattern.compile("\\G\\p{Punct}"); Matcher mat = punct.matcher("this is a test 999"); System.out.println(mat.find()); }
From source file:PositiveLookBehindExample.java
public static void main(String args[]) throws Exception { String regex = "(?<=http://)\\S+"; Pattern pattern = Pattern.compile(regex); String candidate = "The Java2s website can be found at "; candidate += "http://www.java2s.com. There, "; candidate += "you can find some Java examples."; Matcher matcher = pattern.matcher(candidate); while (matcher.find()) { String msg = ":" + matcher.group() + ":"; System.out.println(msg);/* w ww .ja va 2 s . co m*/ } }
From source file:PositiveLookBehindExample.java
public static void main(String args[]) throws Exception { String regex = "(?<=http://)\\S+"; Pattern pattern = Pattern.compile(regex); String candidate = "The Java2s website can be found at "; candidate += "http://www.java2s.com. There, "; candidate += "you can find some best example code for Java."; Matcher matcher = pattern.matcher(candidate); while (matcher.find()) { String msg = ":" + matcher.group() + ":"; System.out.println(msg);// w w w.jav a 2 s.c o m } }