Example usage for java.util.regex Matcher lookingAt

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

Introduction

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

Prototype

public boolean lookingAt() 

Source Link

Document

Attempts to match the input sequence, starting at the beginning of the region, against the pattern.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    Pattern patt = Pattern.compile("(\\w+)\\s(\\d+)");
    Matcher matcher = patt.matcher("Bananas 123");
    matcher.lookingAt();
    System.out.println("Name: " + matcher.group(1));
    System.out.println("Number: " + matcher.group(2));
}

From source file:MainClass.java

public static void main(String[] args) {
    Pattern myRE = Pattern.compile("d.*ian");
    Matcher matcher = myRE.matcher("danian devonian dan");
    matcher.lookingAt();
    String result = matcher.group(0);
    System.out.println(result);//from w ww. j  a v a2  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]);
        if (m1.lookingAt()) // No reset() necessary
            System.out.println("m1.lookingAt() start = " + m1.start() + " end = " + m1.end());

    }/*from   w  w w.j a  va2  s  .c  om*/
}

From source file:RE_QnotU_Args.java

public static void main(String[] argv) {
    String patt = "^Q[^u]\\d+\\.";
    Pattern r = Pattern.compile(patt);
    Matcher m = r.matcher("RE_QnotU_Args");
    boolean found = m.lookingAt();
    System.out.println(patt + (found ? " matches " : " doesn't match ") + "RE_QnotU_Args");

}

From source file:MainClass.java

public static void main(String[] argv) {
    String pattern = "^q[^u]\\d+\\.";
    String input = "QA777. is the next flight.";

    Pattern reCaseInsens = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
    Pattern reCaseSens = Pattern.compile(pattern);

    boolean found;
    Matcher m;
    m = reCaseInsens.matcher(input); // will match any case
    found = m.lookingAt(); // will match any case
    System.out.println("IGNORE_CASE match " + found);

    m = reCaseSens.matcher(input); // Get matcher w/o case-insens flag
    found = m.lookingAt(); // will match case-sensitively
    System.out.println("MATCH_NORMAL match was " + found);

}

From source file:Main.java

public static void main(String args[]) {
    Pattern p = Pattern.compile("test");
    Matcher matcher = p.matcher("this is a test");
    // display the output for the candidate
    System.out.println(matcher.lookingAt());
}

From source file:GetParen0.java

public static void main(String[] args) {
    Pattern myRE = Pattern.compile("d.*ian");
    Matcher matcher = myRE.matcher("darwinian pterodactyls soared over the devonian space");
    matcher.lookingAt();
    String result = matcher.group(0);
    System.out.println(result);//from  w  w w. j a  va  2 s .com
}

From source file:MainClass.java

public static void main(String args[]) {
    Pattern p = Pattern.compile("Java");

    String candidateString_1 = "Java is Java";
    String candidateString_2 = "J2SE is Java";
    String candidateString_3 = "J2SEisJava";

    Matcher matcher = p.matcher(candidateString_1);
    String msg = ":" + candidateString_1 + ": matches?: ";
    System.out.println(msg + matcher.lookingAt());

    matcher.reset(candidateString_2);/*from ww w .  ja va2 s  . c om*/
    msg = ":" + candidateString_2 + ": matches?: ";
    System.out.println(msg + matcher.lookingAt());

    matcher.reset(candidateString_3);
    msg = ":" + candidateString_3 + ": matches?: ";
    System.out.println(msg + matcher.lookingAt());

}

From source file:MatcherLookingAtExample.java

public static void main(String args[]) {
    Pattern p = Pattern.compile("J2SE");

    String candidateString_1 = "J2SE is the only one for me";
    String candidateString_2 = "For me, it's J2SE, or nothing at all";
    String candidateString_3 = "J2SEistheonlyoneforme";

    Matcher matcher = p.matcher(candidateString_1);

    String msg = ":" + candidateString_1 + ": matches?: ";
    System.out.println(msg + matcher.lookingAt());
    matcher.reset(candidateString_2);/*from   w ww  .ja v  a 2s.  co m*/

    msg = ":" + candidateString_2 + ": matches?: ";
    System.out.println(msg + matcher.lookingAt());

    matcher.reset(candidateString_3);

    msg = ":" + candidateString_3 + ": matches?: ";
    System.out.println(msg + matcher.lookingAt());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Compile regular expression
    String patternStr = "b";
    Pattern pattern = Pattern.compile(patternStr);

    // Determine if there is an exact match
    CharSequence inputStr = "a b c";
    Matcher matcher = pattern.matcher(inputStr);
    boolean matchFound = matcher.matches();

    // Try a different input
    matcher.reset("b");
    matchFound = matcher.matches();/*from ww  w  . j a va2  s  .c o  m*/

    // Determine if pattern matches beginning of input
    matchFound = matcher.lookingAt();

}