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 boolean isNumeric(String str) {
    Pattern pattern = Pattern.compile("[0-9]*");
    Matcher isNum = pattern.matcher(str);
    return isNum.matches();
}

From source file:Main.java

public static String replaceBlank(String str) {
    String dest = "";
    if (str != null) {
        Pattern p = Pattern.compile("\\s*");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("");
    }//from w  w w. j  ava  2 s.  c o  m
    return dest;
}

From source file:Main.java

public static boolean isURL(String string) {
    String regExp = "^[\\w]*://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
    Pattern pattern = Pattern.compile(regExp);
    Matcher matcher = pattern.matcher(string);
    return matcher.find();// boolean
}

From source file:Main.java

public static String getFirstMatch(String html, String pattern) {
    Pattern p = Pattern.compile(pattern);
    Matcher m = p.matcher(html);

    String result = "";
    while (m.find()) {
        result = m.group(1);//from   w  w w  . jav a 2  s . c  o m
        break;
    }
    return result;
}

From source file:Main.java

private static boolean match(String str, String rex) {
    if (null == str || str.trim().length() == 0) {
        return false;
    }//  www.  j  av  a  2  s. c  o  m
    Pattern pattern = Pattern.compile(rex);
    Matcher isNum = pattern.matcher(str);
    return isNum.matches();
}

From source file:Main.java

public static boolean isValidUrl(String input) {
    String URL_REGEX = "^((https?|ftp)://|(www|ftp)\\.)?[a-z0-9-]+(\\.[a-z0-9-]+)+([/?].*)?$";

    Pattern p = Pattern.compile(URL_REGEX);
    Matcher m = p.matcher(input);
    if (m.find()) {
        return true;
    }/* w w w  .  j av a  2 s  .c o m*/
    return false;
}

From source file:Main.java

public static String getParameterFromUrl(String param, String url) {
    Pattern p = Pattern.compile(param + "=([^&]+)");
    Matcher m = p.matcher(url);
    m.find();// www  . j a  va  2  s . c  om
    return m.group(1);
}

From source file:Main.java

public static List<String> collect(String str) {
    List<String> list = new ArrayList<String>();
    Pattern p = Pattern.compile("\\[.+?\\]+");
    Matcher m = p.matcher(str);
    while (m.find())
        list.add(m.group());/*from ww w .j  ava 2s  .c  o m*/
    return list;
}

From source file:Main.java

public static boolean validateFileName(String str) {
    if (str.trim().length() == 0) {
        return false;
    }/*  www . ja  va  2 s .  c  o  m*/
    String strPattern = "[^/\\:*?\"<>|]+";
    Pattern p = Pattern.compile(strPattern);
    Matcher m = p.matcher(str);
    return m.matches();
}

From source file:Main.java

public static boolean verifyEmail(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 pattern = Pattern.compile(str);
    Matcher matcher = pattern.matcher(email);
    return matcher.matches();
}