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:io.knotx.knot.service.service.ServiceAttributeUtil.java

private static String extract(String attributeName, int groupIndex) {
    Objects.requireNonNull(attributeName);

    Matcher matcher = ATTR_PATTERN.matcher(attributeName);
    if (matcher.matches()) {
        String namespace = matcher.group(groupIndex);
        return StringUtils.defaultString(namespace);
    } else {//from  ww w . j  a va  2  s .com
        throw new InvalidAttributeException(attributeName);
    }

}

From source file:Main.java

public static String findAppropriateIp() {
    String result = "unknown";

    Enumeration<NetworkInterface> e;
    try {/*from ww w.j  a  v a2s  . c o  m*/
        e = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e1) {
        return result;
    }
    while (e.hasMoreElements()) {
        NetworkInterface n = (NetworkInterface) e.nextElement();
        Enumeration<InetAddress> ee = n.getInetAddresses();
        while (ee.hasMoreElements()) {
            InetAddress inetAddr = ee.nextElement();
            String ipAddr = inetAddr.getHostAddress();

            Matcher m = ipAddrPattern.matcher(ipAddr);
            if (m.matches()) {
                if (!m.group(1).equals("127")) {
                    result = ipAddr;
                }
            }
        }
    }

    return result;
}

From source file:Main.java

public static boolean isValidExp(String exp, String[] columnNames) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < columnNames.length; i++) {
        sb.append(columnNames[i] + "|");
    }/*from ww w . j a v a  2 s  . c  om*/
    String columnRegExp = "(" + sb.substring(0, sb.length() - 1) + ")";
    columnRegExp = columnRegExp.replaceAll(reg3, "Z");
    columnRegExp = columnRegExp.replaceAll(reg4, "Z");

    String aggregateRegExp = reg1 + columnRegExp + reg2;

    exp = exp.replaceAll(reg3, "Z");
    exp = exp.replaceAll(reg4, "Z");

    Pattern p = Pattern.compile(aggregateRegExp);
    Matcher m = p.matcher(exp);
    boolean agg = m.matches();

    p = Pattern.compile(columnRegExp);
    m = p.matcher(exp);
    return agg || m.matches();
}

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

/**
 * This method is used to test whether a string is a valid email address or not
 *
 * @param emailAddress the input string for test
 * @return if the email address is valid return true,otherwise return false.
 *///from  ww  w.  j a  v a 2  s.  c  o  m
public static boolean isValidEmail(String emailAddress) {
    if (emailAddress == null) {
        return false;
    }

    Pattern p = Pattern.compile(EMAIL_REGULAR_EXPRESSION);
    Matcher m = p.matcher(emailAddress);
    return m.matches();
}

From source file:Main.java

/**
 * Decode the setup type integer from the Bluetooth device name.
 * @param bluetoothName/*ww w.  j a  v  a 2s .c  om*/
 * @return The integer value of the setup code, or -1 if no code is present.
 */
public static int getSetupType(String bluetoothName) {
    Matcher matcher = NAME_PATTERN.matcher(bluetoothName);
    if (!matcher.matches()) {
        return -1;
    }

    String typeStr = matcher.group(1);

    if (typeStr != null) {
        try {
            return Integer.parseInt(typeStr);
        } catch (NumberFormatException e) {
            return -1;
        }
    } else {
        return -1;
    }
}

From source file:com.cy.dctms.common.util.ValidateUtil.java

/**
 * ? ????571-88175786?/*from w w  w.  j  a  va 2  s.  c om*/
 * @return false:?; true:?
 * */
public static boolean validatePhone(String telephone) {
    if (StringUtils.isEmpty(telephone)) {
        return false;
    }
    Pattern pattern = Pattern.compile("^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$");
    Matcher macher = pattern.matcher(telephone);
    return macher.matches();
}

From source file:com.cy.dctms.common.util.ValidateUtil.java

/**
 * ? ????57188175786?//w  w w .j a v a 2 s  .co m
 * @return false:?; true:?
 * */
public static boolean validatePhonees(String telephone) {
    if (StringUtils.isEmpty(telephone)) {
        return false;
    }
    Pattern pattern = Pattern.compile("^((0\\d{2,3}))(\\d{7,8})(-(\\d{3,}))?$");
    Matcher macher = pattern.matcher(telephone);
    return macher.matches();
}

From source file:Main.java

@Nullable
static String extractClientSecretFromHtml(@NonNull String html) {
    // quotes around attribute values are optional in HTML5: http://stackoverflow.com/q/6495310/504611
    Pattern clientSecretPattern = Pattern.compile(
            "^.*<meta[ ]+name=['\"]?env-clientSecret['\"]?[ ]+content=['\"]?([^'\"]+)['\"]?.*$",
            Pattern.DOTALL);//from   w  ww  . jav a  2  s .c o  m
    Matcher matcher = clientSecretPattern.matcher(html);
    String clientSecret = null;
    if (matcher.matches()) {
        clientSecret = matcher.group(1);
    }
    return clientSecret;
}

From source file:Main.java

public static CharSequence[] splitLatLon(CharSequence string) {
    Matcher matcherDecimal = PAT_LATLONDEC.matcher(string);
    if (matcherDecimal.matches()) {
        return new String[] { matcherDecimal.group(1).trim(), matcherDecimal.group(2).trim() };
    }//from w  ww.  ja va  2  s.  c  o  m
    Matcher matcher = PAT_LATLON.matcher(string);
    matcher.matches();
    return new String[] { matcher.group(1).trim(), matcher.group(2).trim() };
}

From source file:Main.java

private static String getNodeValue(NodeList nodeList)
        throws TransformerFactoryConfigurationError, TransformerException {

    final Transformer serializer = TransformerFactory.newInstance().newTransformer();
    serializer.setURIResolver(null);//from   w ww  .  j a v a 2 s . c om

    final StringBuilder buf = new StringBuilder();
    for (int i = 0; i < nodeList.getLength(); i++) {
        final StringWriter sw = new StringWriter();
        serializer.transform(new DOMSource(nodeList.item(i)), new StreamResult(sw));
        String xml = sw.toString();
        final Matcher matcher = HEADER_PATTERN.matcher(xml);
        if (matcher.matches()) {
            xml = matcher.group(1);
        }
        buf.append(xml);
        buf.append("\n");
    }

    return buf.toString();
}