Example usage for java.util.regex Matcher group

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

Introduction

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

Prototype

public String group() 

Source Link

Document

Returns the input subsequence matched by the previous match.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String output = "";
    Pattern p = Pattern.compile("\\d");
    Matcher m1 = p.matcher("01234");

    while (m1.find()) {
        System.out.println("\t\t" + m1.group());
    }//ww w  .  j  a v  a 2 s .  c  o  m
    m1.reset("56789");
    System.out.println("After resetting the Matcher");
    while (m1.find()) {
        System.out.println("\t\t" + m1.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 av  a 2  s .c o  m*/
    }
}

From source file:RegExpr7.java

public static void main(String args[]) {
    Pattern pat = Pattern.compile("[a-z]+");
    Matcher mat = pat.matcher("this is a test.");

    while (mat.find())
        System.out.println("Match: " + mat.group());
}

From source file:MainClass.java

public static void main(String args[]) {
    Pattern pat = Pattern.compile("X+");
    Matcher mat = pat.matcher("X XX XXX");

    while (mat.find())
        System.out.println("Match: " + mat.group());
}

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);
    }//from ww  w  . j  a  v  a  2  s.  c  om
}

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   ww w.  j av  a 2s.co  m

}

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:RegExpr5.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: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 duplicatePattern = "\\b(\\w+) \\1\\b";
    Pattern p = Pattern.compile(duplicatePattern);

    int matches = 0;
    String phrase = "this is a test";
    Matcher m = p.matcher(phrase);
    String val = null;
    while (m.find()) {
        val = ":" + m.group() + ":";
        System.out.println(val);
        matches++;//  ww  w .j  a va 2 s. c  o  m
    }
}