List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:MainClass.java
public static void main(String args[]) { String regex = "(\\w+)(\\d\\d)(\\w+)"; Pattern pattern = Pattern.compile(regex); String candidate = "AAA99SuperJava"; 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:MainClass.java
public static void main(String args[]) { // Match lowercase words. Pattern pat = Pattern.compile("[a-z]+"); Matcher mat = pat.matcher("www.java2s.com."); while (mat.find()) System.out.println("Match: " + mat.group()); }
From source file:TestRegularExpression.java
public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage:\n" + "java TestRegularExpression " + "characterSequence regularExpression+"); System.exit(0);//from w ww.j a v a 2 s . c o m } System.out.println("Input: \"" + args[0] + "\""); for (int i = 1; i < args.length; i++) { System.out.println("Regular expression: \"" + args[i] + "\""); Pattern p = Pattern.compile(args[i]); Matcher m = p.matcher(args[0]); while (m.find()) { System.out.println("Match \"" + m.group() + "\" at positions " + m.start() + "-" + (m.end() - 1)); } } }
From source file:MatcherEndExample.java
public static void main(String args[]) { String candidateString = "My name is Bond. James Bond."; String matchHelper[] = { " ^", " ^" }; Pattern p = Pattern.compile("Bond"); Matcher matcher = p.matcher(candidateString); matcher.find(); int endIndex = matcher.end(); System.out.println(candidateString); System.out.println(matchHelper[0] + endIndex); matcher.find();/* w w w.j av a 2s.c o m*/ int nextIndex = matcher.end(); System.out.println(candidateString); System.out.println(matchHelper[1] + nextIndex); }
From source file:ReluctantExample.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()); }/* w w w . jav a 2s .c o m*/ System.out.println("Done"); }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharSequence inputStr = "a\rb"; inputStr = "a\r\nb"; inputStr = "a\nb"; String patternStr = "^(.*)$"; Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE); Matcher matcher = pattern.matcher(inputStr); while (matcher.find()) { String lineWithTerminator = matcher.group(0); String lineWithoutTerminator = matcher.group(1); }// w w w . j a va2 s . c o m }
From source file:Grep.java
public static void main(String args[]) throws Exception { String regex = ""; InputStream in = System.in; regex = args[0];/*ww w. j a v a 2s . com*/ in = new BufferedInputStream(new FileInputStream(args[1])); Pattern p = null; p = Pattern.compile(regex); BufferedReader buff = new BufferedReader(new InputStreamReader(in)); String a; for (a = buff.readLine(); a != null; a = buff.readLine()) { Matcher m = p.matcher(a); if (m.find()) { System.out.println(a); } } }
From source file:MainClass.java
public static void main(String args[]) { // create regular expression Pattern expression = Pattern.compile("J.*\\d[0-35-9]-\\d\\d-\\d\\d"); String string1 = "Jack's Birthday is 05-12-75\n" + "Joe's Birthday is 11-04-68\n" + "Tom's Birthday is 04-28-73\n" + "Lee" + "s Birthday is 12-17-77"; // match regular expression to string and print matches Matcher matcher = expression.matcher(string1); while (matcher.find()) System.out.println(matcher.group()); }
From source file:Main.java
public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); Matcher m = p.matcher(INPUT); // get a matcher object while (m.find()) { System.out.println("start(): " + m.start()); System.out.println("end(): " + m.end()); }/*w w w . j a v a 2s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharSequence inputStr = "a\r\rb"; // Mac //inputStr = "a\r\n\r\nb"; // Windows //inputStr = "a\n\nb"; // Unix String patternStr = "(^.*\\S+.*$)+"; Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE); Matcher matcher = pattern.matcher(inputStr); while (matcher.find()) { String paragraph = matcher.group(); }//from www . j a va2s. com }