Example usage for java.util.regex Pattern matcher

List of usage examples for java.util.regex Pattern matcher

Introduction

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

Prototype

public Matcher matcher(CharSequence input) 

Source Link

Document

Creates a matcher that will match the given input against this pattern.

Usage

From source file:Main.java

public static String subString(String sub) {
    Pattern pp = Pattern.compile("\\s*|\t|\r|\n");
    Matcher mm = pp.matcher(sub);
    return mm.replaceAll("");
}

From source file:Main.java

public static boolean isEmail(String email) {

    String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    Pattern p = Pattern.compile(str);
    Matcher m = p.matcher(email);
    return m.matches();

    /*/* w  w  w  .ja  va  2 s .c o  m*/
     * if (email != null && email.contains("@")) { return true; } else {
     * return false; }
     */
}

From source file:Main.java

public static boolean isUrl(String url) {
    String regex = "^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
    Pattern patt = Pattern.compile(regex);
    Matcher matcher = patt.matcher(url);
    return matcher.matches();
}

From source file:Main.java

public static boolean isGpsLng(String gpsLng) {
    Pattern p = Pattern.compile(GPS_LNG_REGULAR);
    Matcher m = p.matcher(gpsLng);
    return m.matches();
}

From source file:Main.java

public static boolean checkBalanceFormat(String balance) {
    String reg = "^(([1-9]\\d*)|0)(\\.\\d{1,2})?$";
    Pattern p = Pattern.compile(reg);
    Matcher matcher = p.matcher(balance);
    if (matcher.matches()) {
        return true;
    }//from  w ww .jav  a2 s  .c  o m
    return false;
}

From source file:Main.java

public static String replace(String string) {
    Pattern pattern = Pattern.compile(".*?");
    Matcher matcher = pattern.matcher(string);
    return matcher.replaceAll("$1").trim();
}

From source file:Main.java

private static boolean Regular(String str, String pattern) {
    if (null == str || str.trim().length() <= 0)
        return false;
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(str);
    return m.matches();
}

From source file:Main.java

public static boolean checkEmail(String s) {
    String check = "^([a-z0-9A-Z_-]+[-|\\.]?)+[a-z0-9A-Z_]@([a-z0-9A-Z_]+(-[a-z0-9A-Z_]+)?\\.)+[a-zA-Z\\.]{2,}$";
    Pattern regex = Pattern.compile(check);
    Matcher matcher = regex.matcher(s);
    return matcher.matches();
}

From source file:Main.java

public static boolean isLetter(String str) {
    if (str == null || str.length() < 0) {
        return false;
    }/*from  ww w.jav  a  2s . com*/
    Pattern pattern = Pattern.compile("[\\w\\.-_]*");
    return pattern.matcher(str).matches();
}

From source file:Main.java

public static boolean checkEmailValid(String email) {
    if ((email == null) || (email.trim().length() == 0)) {
        return false;
    }/*from   w w  w  .  ja  v a  2s .  c  o m*/
    String regEx = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(email.trim().toLowerCase());

    return m.find();
}