Example usage for java.util.regex Matcher matches

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

Introduction

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

Prototype

public boolean matches() 

Source Link

Document

Attempts to match the entire region against the pattern.

Usage

From source file:Main.java

public static String smartMediaName(String fileName) {
    String reg = "WinG|ENG|aAf|3D|720P|720p|1080P|1080p|X264|DTS|BluRay|Bluray|HSBS|x264|CHD|H-SBS|"
            + "Wiki|WiKi|ML|RemuX|CnSCG|HDChina|Sample|sample|AVC|MA|5.1|AC3|AAC|rip|265|"
            + "HDTV|DL|DHD|HD|HEVC|DiCH|dich|dhd|hdtv|Pix|BAWLS|hv|NG";
    //reduce ext/*from  w  w w . j av a  2  s. c om*/
    String result = fileName.substring(0, fileName.lastIndexOf("."));
    //reduce other word like 720P,DTS,X264..
    result = result.replaceAll(reg, "");
    //reduce last .
    String endReg = "[0-9]|[|]|.| |-";
    String endX = "0123456789.-[] ";
    Pattern pattern = Pattern.compile(endReg, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(result);
    if (matcher.matches()) {
        return result;
    }
    if (result.length() > 2) {
        String endChar = result.substring(result.length() - 1, result.length());
        while (endX.contains(endChar)) {
            result = result.substring(0, result.length() - 1);
            if (result.length() > 2) {
                endChar = result.substring(result.length() - 1, result.length());
            } else {
                break;
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Handle range form like x3-12//  ww w  .  j  a v  a2  s.com
 *
 * @param rs Range List
 * @param r Range Token
 */
private static boolean range0(List<String> rs, String r) {
    Matcher matcher = range0Pattern.matcher(r);
    if (!matcher.matches())
        return false;

    String prefix = matcher.group(1);
    int begin = Integer.parseInt(matcher.group(2));
    int end = Integer.parseInt(matcher.group(3));
    for (int i = begin; i <= end; ++i) {
        rs.add(prefix + i);
    }
    return true;
}

From source file:Main.java

public static boolean isMobileNO(String cellphone) {
    Pattern p = Pattern.compile("^[1][34578]\\d{9}$");
    Matcher m = p.matcher(cellphone);
    if (!TextUtils.isEmpty(cellphone)) {
        return m.matches();
    }//from w w w  .j  a v  a  2  s.  co m
    return false;
}

From source file:Main.java

/**
 * Parses an RFC 5545 UTC offset and returns milliseconds.
 * //from  w w  w. j  a v  a2s . co  m
 * Grammar:
 *        utc-offset = time-numzone
 *        time-numzone = ("+" / "-") time-hour time-minute [time-second]
 */
public static int parseUtcOffset(String value) {
    final Pattern utcOffsetPattern = Pattern.compile("([-+])(\\d{1,2})(\\d{2})(?:\\d{2})?");
    final Matcher matcher = utcOffsetPattern.matcher(value);
    if (!matcher.matches()) {
        throw new IllegalArgumentException(value);
    }
    int sign = matcher.group(1).equals("+") ? 1 : -1;
    int hours = Integer.parseInt(matcher.group(2));
    int minutes = Integer.parseInt(matcher.group(3));
    int offsetSeconds = sign * (hours * 60 + minutes) * 60;
    return offsetSeconds * 1000;
}

From source file:Main.java

public static Rectangle parseRectangle(String s) {
    if (rectanglePattern == null)
        rectanglePattern = Pattern.compile("\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*");

    Matcher m = rectanglePattern.matcher(s);

    if (m.matches()) {
        return new Rectangle(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)),
                Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4)));
    }//from  w  ww . ja v a 2  s. co m
    return null;
}

From source file:Main.java

public static boolean isPhoneNumber(String handset) {
    try {//from  www  .  j a  v  a2  s .co  m
        if (!handset.substring(0, 1).equals("1")) {
            return false;
        }
        if (handset == null || handset.length() != 11) {
            return false;
        }
        String check = "^[0123456789]+$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(handset);
        boolean isMatched = matcher.matches();
        if (isMatched) {
            return true;
        } else {
            return false;
        }
    } catch (RuntimeException e) {
        return false;
    }
}

From source file:Main.java

public static final boolean isProcessedMobilePhoneNumber(CharSequence target) {

    if (target != null || TextUtils.isEmpty(target) == false) {
        Matcher numberMatcher = mauritianProcessedMobilePhoneNumber.matcher(target);
        return numberMatcher.matches();
    }/*from   ww  w  .j a va2  s. c o  m*/

    return false;
}

From source file:com.changhong.app.utils.ValidatorUtils.java

public static boolean isPositiveInteger(String number) {
    if (number == null) {
        return false;
    }/*w w w  .  ja  v  a2s.c  o  m*/

    Pattern p = Pattern.compile(POSITIVE_INTEGER_REGULAR_EXPRESSION);
    Matcher m = p.matcher(number);
    return m.matches();
}

From source file:Main.java

/**
 * get innerHtml from href/*from   ww w.  ja  va2 s . c  o m*/
 * 
 * <pre>
 * getHrefInnerHtml(null)                                  = ""
 * getHrefInnerHtml("")                                    = ""
 * getHrefInnerHtml("mp3")                                 = "mp3";
 * getHrefInnerHtml("&lt;a innerHtml&lt;/a&gt;")                    = "&lt;a innerHtml&lt;/a&gt;";
 * getHrefInnerHtml("&lt;a&gt;innerHtml&lt;/a&gt;")                    = "innerHtml";
 * getHrefInnerHtml("&lt;a&lt;a&gt;innerHtml&lt;/a&gt;")                    = "innerHtml";
 * getHrefInnerHtml("&lt;a href="baidu.com"&gt;innerHtml&lt;/a&gt;")               = "innerHtml";
 * getHrefInnerHtml("&lt;a href="baidu.com" title="baidu"&gt;innerHtml&lt;/a&gt;") = "innerHtml";
 * getHrefInnerHtml("   &lt;a&gt;innerHtml&lt;/a&gt;  ")                           = "innerHtml";
 * getHrefInnerHtml("&lt;a&gt;innerHtml&lt;/a&gt;&lt;/a&gt;")                      = "innerHtml";
 * getHrefInnerHtml("jack&lt;a&gt;innerHtml&lt;/a&gt;&lt;/a&gt;")                  = "innerHtml";
 * getHrefInnerHtml("&lt;a&gt;innerHtml1&lt;/a&gt;&lt;a&gt;innerHtml2&lt;/a&gt;")        = "innerHtml2";
 * </pre>
 * 
 * @param href
 * @return <ul>
 *         <li>if href is null, return ""</li>
 *         <li>if not match regx, return source</li>
 *         <li>return the last string that match regx</li>
 *         </ul>
 */
public static String getHrefInnerHtml(String href) {
    if (isEmpty(href)) {
        return "";
    }

    String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*";
    Pattern hrefPattern = Pattern.compile(hrefReg, Pattern.CASE_INSENSITIVE);
    Matcher hrefMatcher = hrefPattern.matcher(href);
    if (hrefMatcher.matches()) {
        return hrefMatcher.group(1);
    }
    return href;
}

From source file:com.changhong.app.utils.ValidatorUtils.java

public static boolean isValidIpAddress(String ipAddress) {
    if (ipAddress == null) {
        return false;
    }// w ww .  jav  a 2s. c  o  m

    Pattern p = Pattern.compile(IPADDRESS_REGULAR_EXPRESSION);
    Matcher m = p.matcher(ipAddress);
    return m.matches();
}