Example usage for java.util.regex Matcher end

List of usage examples for java.util.regex Matcher end

Introduction

In this page you can find the example usage for java.util.regex Matcher end.

Prototype

public int end() 

Source Link

Document

Returns the offset after the last character matched.

Usage

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);

    matcher.find();/*from w ww.  ja va 2 s. com*/
    int endIndex = matcher.end();
    System.out.println(candidateString);
    System.out.println(endIndex);

}

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();/*from w ww  .  j  a va2s . com*/
    int endIndex = matcher.end();
    System.out.println(candidateString);
    System.out.println(matchHelper[0] + endIndex);

    matcher.find();
    int nextIndex = matcher.end();
    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(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()));
    }//from w w  w.ja  v a  2 s.com
}

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);/* w ww  .j a  va 2 s . c om*/
    }
    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:TestRegularExpression.java

public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage:\n" + "java TestRegularExpression " + "characterSequence regularExpression+");
        System.exit(0);//w  w  w. ja  va2s  . com
    }
    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);
    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  .  ja  va  2 s  .com
}

From source file:MainClass.java

public static void main(String[] args) {
    String[] input = new String[] { "Java has regular expressions in 1.4",
            "regular expressions now expressing in Java", "Java represses oracular expressions" };

    Pattern p1 = Pattern.compile("re\\w*"), p2 = Pattern.compile("Java.*");

    for (int i = 0; i < input.length; i++) {
        System.out.println("input " + i + ": " + input[i]);
        Matcher m1 = p1.matcher(input[i]), m2 = p2.matcher(input[i]);
        while (m1.find())
            System.out.println("m1.find() '" + m1.group() + "' start = " + m1.start() + " end = " + m1.end());
    }/*from  w ww  . jav  a  2 s  . c  o  m*/
}

From source file:MainClass.java

public static void main(String[] args) {
    String[] input = new String[] { "Java has regular expressions in 1.4",
            "regular expressions now expressing in Java", "Java represses oracular expressions" };

    Pattern p1 = Pattern.compile("re\\w*"), p2 = Pattern.compile("Java.*");

    for (int i = 0; i < input.length; i++) {
        System.out.println("input " + i + ": " + input[i]);
        Matcher m1 = p1.matcher(input[i]), m2 = p2.matcher(input[i]);
        if (m1.lookingAt()) // No reset() necessary
            System.out.println("m1.lookingAt() start = " + m1.start() + " end = " + m1.end());

    }/* w  ww.ja va 2s . c om*/
}

From source file:StartEnd.java

public static void main(String[] args) {
    String[] input = new String[] { "Java has regular expressions in 1.4",
            "regular expressions now expressing in Java", "Java represses oracular expressions" };
    Pattern p1 = Pattern.compile("re\\w*"), p2 = Pattern.compile("Java.*");
    for (int i = 0; i < input.length; i++) {
        System.out.println("input " + i + ": " + input[i]);
        Matcher m1 = p1.matcher(input[i]), m2 = p2.matcher(input[i]);
        while (m1.find())
            System.out.println("m1.find() '" + m1.group() + "' start = " + m1.start() + " end = " + m1.end());
        while (m2.find())
            System.out.println("m2.find() '" + m2.group() + "' start = " + m2.start() + " end = " + m2.end());
        if (m1.lookingAt()) // No reset() necessary
            System.out.println("m1.lookingAt() start = " + m1.start() + " end = " + m1.end());
        if (m2.lookingAt())
            System.out.println("m2.lookingAt() start = " + m2.start() + " end = " + m2.end());
        if (m1.matches()) // No reset() necessary
            System.out.println("m1.matches() start = " + m1.start() + " end = " + m1.end());
        if (m2.matches())
            System.out.println("m2.matches() start = " + m2.start() + " end = " + m2.end());
    }// ww w  .  j ava 2 s. c  om
}

From source file:HrefMatch.java

public static void main(String[] args) {
    try {//from w  ww  .jav a2 s . c o  m
        // get URL string from command line or use default
        String urlString;
        if (args.length > 0)
            urlString = args[0];
        else
            urlString = "http://java.sun.com";

        // open reader for URL
        InputStreamReader in = new InputStreamReader(new URL(urlString).openStream());

        // read contents into string builder
        StringBuilder input = new StringBuilder();
        int ch;
        while ((ch = in.read()) != -1)
            input.append((char) ch);

        // search for all occurrences of pattern
        String patternString = "<a\\s+href\\s*=\\s*(\"[^\"]*\"|[^\\s>]*)\\s*>";
        Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            int start = matcher.start();
            int end = matcher.end();
            String match = input.substring(start, end);
            System.out.println(match);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (PatternSyntaxException e) {
        e.printStackTrace();
    }
}