List of usage examples for java.util.regex Matcher start
public int start()
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()); }//from www . ja v a 2s. co m }
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()); }/*w w w . java 2 s . c o m*/ }
From source file:MainClass.java
public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage:\n" + "java MainClass " + "characterSequence regularExpression+"); System.exit(0);/* www . ja va2 s . co 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:Main.java
public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); // get a matcher object Matcher m = p.matcher(INPUT); List<String> sequences = new Vector<String>(); while (m.find()) { sequences.add(INPUT.substring(m.start(), m.end())); }// w w w . ja va 2s . com }
From source file:MainClass.java
public static void main(String args[]) { Pattern pat = Pattern.compile("java"); Matcher mat = pat.matcher("www.java2s.com 1 2 3 j a v a 2 s.c o m"); while (mat.find()) { System.out.println("java found at index " + mat.start()); }// w ww . j a v a 2s .c o m }
From source file:MainClass.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); // Find the starting point of the first 'Bond' matcher.find();/*from ww w .jav a2s. c o m*/ int startIndex = matcher.start(); System.out.println(candidateString); System.out.println(matchHelper[0] + startIndex); }
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 w w . ja 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: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); // Find the starting point of the first 'test' matcher.find();//from w w w. jav a 2 s .co m int startIndex = matcher.start(); System.out.println(candidateString); System.out.println(startIndex); // Find the starting point of the second 'test' matcher.find(); int nextIndex = matcher.start(); System.out.println(candidateString); System.out.println(nextIndex); }
From source file:MatcherStartExample.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); //Find the starting point of the first 'Bond' matcher.find();/* w w w .j a v a2 s. c o m*/ int startIndex = matcher.start(); System.out.println(candidateString); System.out.println(matchHelper[0] + startIndex); //Find the starting point of the second 'Bond' matcher.find(); int nextIndex = matcher.start(); System.out.println(candidateString); System.out.println(matchHelper[1] + nextIndex); }
From source file:Main.java
public static void main(String[] args) { Pattern p = Pattern.compile("\\d\\d?\\d?"); Matcher m = p.matcher("test this 536 in it"); while (m.find()) { System.out.println(m.group()); // print the age in your string System.out.println(m.start()); // print the position in the string where it starts }//from w w w. jav a 2s . c om }