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:com.cy.swp.common.util.ValidateUtil.java

/**
 * ???/*from  w  w w  . j a  va2s  .c o m*/
 * @param carNumber
 * @return
 */

public static boolean validateCarNumber(String carNumber) {
    if (StringUtils.isEmpty(carNumber)) {
        return false;
    }
    Pattern pattern = Pattern.compile(
            "^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$|^[a-zA-Z]{2}\\d{7}$");
    Matcher macher = pattern.matcher(carNumber);
    return macher.matches();
}

From source file:io.redlink.sdk.util.ApiHelper.java

/**
 * Build a proper api version//www  .jav a 2s . co  m
 *
 * @param version raw version
 * @return api version
 * @see <a href="http://dev.redlink.io/sdk#introduction">api/sdk versioning</a>
 */
public static String getApiVersion(String version) {
    if (StringUtils.isBlank(version)) {
        return null;
    } else {
        final Matcher matcher = VERSION_PATTERN.matcher(version);
        if (matcher.matches()) {
            if (StringUtils.isBlank(matcher.group(4))) {
                return String.format("%s.%s", matcher.group(1), matcher.group(2));
            } else {
                return String.format("%s.%s-%s", matcher.group(1), matcher.group(2), matcher.group(4));
            }
        } else {
            return null;
        }
    }
}

From source file:com.alu.e3.prov.lifecycle.IDHelper.java

/**
 * Extract datas from the given filename.
 * @param fileName//from   w  w w  .j a v a 2  s. co m
 * @return a String[] containing respectively: { apiIDEncoded, apiID, provID }
 */
public static String[] extractAllFromFileName(String fileName) {
    Pattern p = Pattern.compile("([a-f0-9]+)-([a-f0-9]+)\\.[a-z]{3}");
    Matcher m = p.matcher(fileName);
    if (!m.matches())
        return null;

    String apiIDEncoded = m.group(1);
    String apiID = null;
    try {
        apiID = IDHelper.decode(apiIDEncoded);
    } catch (RuntimeException e) {
        e.printStackTrace();
        if (logger.isErrorEnabled()) {
            logger.error("Undecodable apiId:{}", apiIDEncoded);
        }
    }
    String provID = m.group(2);

    String[] datas = new String[] { apiIDEncoded, apiID, provID };

    return datas;
}

From source file:hudson.plugins.sonar.utils.SonarUtils.java

/**
 * Read logs of the build to find URL of the project dashboard in Sonar
 *//*from   w  w w .  jav a 2  s . c o m*/
public static String extractSonarProjectURLFromLogs(AbstractBuild<?, ?> build) throws IOException {
    BufferedReader br = null;
    String url = null;
    try {
        br = new BufferedReader(build.getLogReader());
        String strLine;
        while ((strLine = br.readLine()) != null) {
            Pattern p = Pattern.compile(URL_PATTERN_IN_LOGS);
            Matcher match = p.matcher(strLine);
            if (match.matches()) {
                url = match.group(1);
            }
        }
    } finally {
        IOUtils.closeQuietly(br);
    }
    return url;
}

From source file:Utilities.java

/**
 * Determine if the given string is a valid IPv4 or IPv6 address.  This method
 * uses pattern matching to see if the given string could be a valid IP address.
 *
 * @param ipAddress A string that is to be examined to verify whether or not
 *  it could be a valid IP address.//from ww w . j  ava  2 s . c  o m
 * @return <code>true</code> if the string is a value that is a valid IP address,
 *  <code>false</code> otherwise.
 */
public static boolean isIpAddress(String ipAddress) {

    Matcher m1 = Utilities.VALID_IPV4_PATTERN.matcher(ipAddress);
    if (m1.matches()) {
        return true;
    }
    Matcher m2 = Utilities.VALID_IPV6_PATTERN.matcher(ipAddress);
    return m2.matches();
}

From source file:Main.java

public static String getHrefInnerHtml(String href) {

    if (isEmpty(href)) {
        return "";
    }//from  ww w  .j a  v a 2 s.c  o  m

    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.cognifide.slice.util.InjectorNameUtil.java

/**
 * This util provides injector name for a given resource. The name is read from second part of the
 * resource type, i.e. part after /apps/. For instance, for /apps/myapp/someresource, it will return
 * <code>myapp</code> <br>
 * <br>/*  w ww .j  a v a 2s .  com*/
 * Please note that this method is deprecated and it doesn't support injectors registered for a given path
 * (with use of {@link InjectorRunner#setInjectorPath(String)})
 * 
 * @deprecated use {@link InjectorsRepository#getInjectorNameForResource(String)} instead
 * 
 * @param resourceType resource type to take the injector name from
 * @return injector name, always second part of the resource type
 */
@Deprecated
public static String getFromResourceType(String resourceType) {
    String injectorName = null;
    if (StringUtils.isNotEmpty(resourceType)) {
        Pattern pattern = RESOURCE_TYPE_PATTERN;
        Matcher matcher = pattern.matcher(resourceType);
        if (matcher.matches()) {
            injectorName = matcher.group(2);
        }
    }
    return injectorName;
}

From source file:edu.umn.msi.tropix.proteomics.conversion.DtaNameUtils.java

public static DtaNameSummary getDtaNameSummary(final String filename) {
    final Matcher matcher = DTA_PATTERN.matcher(FilenameUtils.getName(filename));
    matcher.matches();
    final String basename = matcher.group(1);
    final int start = Integer.parseInt(matcher.group(2));
    final int end = Integer.parseInt(matcher.group(3));
    final short charge = Short.parseShort(matcher.group(4));
    return new DtaNameSummary(basename, start, end, charge);
}

From source file:Main.java

public static int[] parseIntegerList(String list, int minValue, int maxValue) {
    ArrayList tmpList = new ArrayList();
    Pattern p = Pattern.compile("(\\d*)-(\\d*)");
    String[] a = list.replace(',', ' ').split("\\s+");
    int i = a.length;

    for (int i$ = 0; i$ < i; ++i$) {
        String token = a[i$];/*w ww.  j  a va 2s . c o m*/

        try {
            if (token.matches("\\d+")) {
                tmpList.add(Integer.valueOf(Integer.parseInt(token)));
            } else {
                Matcher e = p.matcher(token);

                if (e.matches()) {
                    String a1 = e.group(1);
                    String b = e.group(2);
                    int min = a1.equals("") ? minValue : Integer.parseInt(a1);
                    int max = b.equals("") ? maxValue : Integer.parseInt(b);

                    for (int i1 = min; i1 <= max; ++i1) {
                        tmpList.add(Integer.valueOf(i1));
                    }
                }
            }
        } catch (NumberFormatException var15) {
            ;
        }
    }

    if (minValue <= maxValue) {
        int var16 = 0;

        while (var16 < tmpList.size()) {
            if (((Integer) tmpList.get(var16)).intValue() >= minValue
                    && ((Integer) tmpList.get(var16)).intValue() <= maxValue) {
                ++var16;
            } else {
                tmpList.remove(var16);
            }
        }
    }

    int[] var17 = new int[tmpList.size()];

    for (i = 0; i < var17.length; ++i) {
        var17[i] = ((Integer) tmpList.get(i)).intValue();
    }

    return var17;
}

From source file:com.ge.predix.uaa.token.lib.HttpServletRequestUtil.java

/**
 * @return empty string if requestHostname and baseDomain are identical, null if domain is not a sub-string of
 *         requestHostname//from   ww  w .j  a  v a2 s .  c om
 */
static String getZoneNameFromRequestHostName(final String requestHostname, final String baseDomain) {

    if (requestHostname.equals(baseDomain)) {
        return "";
    }

    String regexPattern = "^(.*?)\\." + Pattern.quote(baseDomain) + "$";
    Pattern pattern = Pattern.compile(regexPattern);
    Matcher matcher = pattern.matcher(requestHostname);
    if (!matcher.matches()) {
        // There is no zone scope for this request. Return null
        return null;
    }

    String subdomain = matcher.group(1);

    return subdomain;
}