Example usage for java.util.regex Matcher find

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

Introduction

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

Prototype

public boolean find() 

Source Link

Document

Attempts to find the next subsequence of the input sequence that matches the pattern.

Usage

From source file:Main.java

public static void main(String[] args) {
    String s = new String("\"Hello\" hello");
    Pattern p = Pattern.compile("\"([^\"]*)\"");
    Matcher m = p.matcher(s);
    while (m.find()) {
        System.out.println(m.group(1));
    }/*from   w w w. ja v a 2  s  .  co  m*/
}

From source file:Main.java

public static void main(String[] args) {
    String s = "stuff1 (foo1(bar1)foo2) stuff2 (bar2) stuff3";
    String re = "\\([^()]*\\)";
    Pattern p = Pattern.compile(re);
    Matcher m = p.matcher(s);
    while (m.find()) {
        s = m.replaceAll("");
        m = p.matcher(s);/* w w  w . j  a  va2 s  . c  o  m*/
    }
    System.out.println(s);
}

From source file:Main.java

public static void main(String[] args) {
    String regex = "[a-z]@.";
    Pattern p = Pattern.compile(regex);
    String str = "abc@yahoo.com,123@cnn.com,abc@google.com";
    Matcher m = p.matcher(str);

    if (m.find()) {
        String foundStr = m.group();
        System.out.println("Found text is:" + foundStr);
    }// w w w  . j a va  2  s .  co m
}

From source file:Main.java

public static void main(String[] args) {
    String s = "bla bla {a.b.c} bla bla bla {0,1,2} bla bla";
    Pattern p = Pattern.compile("\\{([^\\{\\}]*)\\}");

    Matcher m = p.matcher(s);

    while (m.find()) {
        System.out.println(m.group(1));
    }//from w w w  .j a v a 2  s .  co  m
}

From source file:RegExpr4.java

public static void main(String args[]) {
    Pattern pat = Pattern.compile("W+");
    Matcher mat = pat.matcher("W WW WWW");

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

From source file:Main.java

public static void main(String[] args) {
    String regex = "\\b(\\d{3})(\\d{3})(\\d{4})\\b";

    Pattern p = Pattern.compile(regex);
    String source = "1234567890, 12345,  and  9876543210";

    Matcher m = p.matcher(source);

    while (m.find()) {
        System.out.println("Phone: " + m.group() + ", Formatted Phone:  (" + m.group(1) + ") " + m.group(2)
                + "-" + m.group(3));
    }//from w  w w .j a v a  2s .c  om
}

From source file:Main.java

public static void main(String[] args) {
    String str = "This is a 23.4.123 test.";
    String[] s = str.split(" ");
    Pattern p = Pattern.compile("(\\d)+\\.(\\d)+");
    double d;//  w  w w. j  a  v a 2  s . c  o  m
    for (int i = 0; i < s.length; i++) {
        Matcher m = p.matcher(s[i]);
        while (m.find()) {
            d = Double.parseDouble(m.group());
            System.out.println(d);
        }
    }
}

From source file:Main.java

public static void main(String args[]) {

    // String to be scanned to find the pattern.
    String line = "this is a test";
    String pattern = "is";

    // Create a Pattern object
    Pattern r = Pattern.compile(pattern);

    // Now create matcher object.
    Matcher m = r.matcher(line);
    if (m.find()) {
        System.out.println("Found the value");
    } else {//  www.j a v  a  2 s  .  c  o m
        System.out.println("NO MATCH");
    }
}

From source file:MainClass.java

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

    while (m1.find()) {
        System.out.println("\t\t" + m1.group());
    }//w w  w.j  av  a 2  s. c  o m
    m1.reset();
    System.out.println("After resetting the Matcher");
    while (m1.find()) {
        System.out.println("\t\t" + m1.group());
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Pattern p = Pattern.compile("\\w\\d");
    String candidate = "A6 is my favorite";

    Matcher matcher = p.matcher(candidate);

    if (matcher.find()) {
        String tmp = matcher.group(0);
        System.out.println(tmp);// ww  w  .  j a v  a 2s .  c  o m
    }
}