java.util.regex.Pattern#matches ( )源码实例Demo

下面列出了java.util.regex.Pattern#matches ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private boolean isAccountNameValid(String accountName) {
    boolean result;
    if (!isLengthMatches(accountName)) {
        failMessage = String.format("Account name cannot be null and it's value must be in the range of min %d and max %d characters. Current: %d",
                MIN_ACCOUNT_NAME_LENGTH,
                MAX_ACCOUNT_NAME_LENGTH,
                StringUtils.length(accountName));
        result = false;
    } else if (!Pattern.matches("^[a-z0-9]*", accountName)) {
        failMessage = "Account name must contain only numbers and lowercase letters";
        result = false;
    } else {
        result = true;
    }
    return result;
}
 
源代码2 项目: hottub   文件: JAXWSUtils.java
public static boolean matchQNames(QName target, QName pattern) {
    if ((target == null) || (pattern == null))  {
        // if no service or port is in descriptor
        return false;
    }
    if (pattern.getNamespaceURI().equals(target.getNamespaceURI())) {
        String regex = pattern.getLocalPart().replaceAll("\\*",  ".*");
        return Pattern.matches(regex, target.getLocalPart());
    }
    return false;
}
 
源代码3 项目: pcgen   文件: PCEqTypeTermEvaluator.java
@Override
public Float resolve(PlayerCharacter pc)
{
	final String sTok = evaluate(pc);

	if (Pattern.matches(FP_REGEX, sTok))
	{
		return TermUtil.convertToFloat(originalText, sTok);
	}

	return 0.0f;
}
 
源代码4 项目: WebCollector   文件: Page.java
/**
 * 判断当前Page的Http响应头的Content-Type是否符合正则
 *
 * @param contentTypeRegex
 * @return
 */
public boolean matchContentType(String contentTypeRegex) {
    if (contentTypeRegex == null) {
        return contentType() == null;
    }
    return Pattern.matches(contentTypeRegex, contentType());
}
 
protected SimplePrincipal getSimplePrincipal(final String name, final boolean isNtlm) {
    if (this.principalWithDomainName) {
        return new SimplePrincipal(name);
    }
    if (isNtlm) {
        return Pattern.matches("\\S+\\\\\\S+", name)
                ? new SimplePrincipal(name.split("\\\\")[1])
                : new SimplePrincipal(name);
    }
    return new SimplePrincipal(name.split("@")[0]);
}
 
源代码6 项目: zeppelin   文件: ResourceSet.java
public ResourceSet filterByClassnameRegex(String regex) {
  ResourceSet result = new ResourceSet();
  for (Resource r : this) {
    if (Pattern.matches(regex, r.getClassName())) {
      result.add(r);
    }
  }
  return result;
}
 
源代码7 项目: openzaly   文件: ValidatorPattern.java
/**
 * 校验邮箱
 * 
 * @param email
 * @return 校验通过返回true,否则返回false
 */
public static boolean isEmail(String email) {
	if (email == null) {
		return false;
	}
	return Pattern.matches(REGEX_EMAIL, email);
}
 
源代码8 项目: aion_api   文件: SString.java
/**
 * Checks that inputted string is the correct type. To be used with ABI.
 *
 * @param in Solidity Type.
 * @return returns a boolean indicating the type is SString.
 */
public boolean isType(String in) {
    if (in == null) {
        LOGGER.error("[isType] {}", ErrId.getErrString(-315L));
        return false;
    }
    return Pattern.matches("^string(\\[([0-9]*)])*$", in);
}
 
源代码9 项目: flexy-pool   文件: DBCPPoolAdapter.java
/**
 * {@inheritDoc}
 */
@Override
protected boolean isAcquireTimeoutException(Exception e) {
    return e.getMessage() != null && Pattern.matches(ACQUIRE_TIMEOUT_MESSAGE, e.getMessage());
}
 
源代码10 项目: jdk8u-jdk   文件: ConnectionTest.java
/**
 * Checks the connection id for validity.
 * The {@link
 * javax.management.remote package description} describes the
 * conventions for connection IDs.
 * @param proto Connection protocol
 * @param clientConnId The connection ID
 * @return Returns {@code true} if the connection id conforms to the specification; {@code false} otherwise.
 * @throws Exception
 */
private static boolean checkConnectionId(String proto, String clientConnId)
        throws Exception {
    StringTokenizer tok = new StringTokenizer(clientConnId, " ", true);
    String s;
    s = tok.nextToken();
    if (!s.startsWith(proto + ":")) {
        System.out.println("Expected \"" + proto + ":\", found \"" + s +
                           "\"");
        return false;
    }

    int hostAddrInd = s.indexOf("//");
    if (hostAddrInd > -1) {
        s = s.substring(hostAddrInd + 2);
        if (!Pattern.matches(IPV4_PTN, s)) {
            if (!s.startsWith("[") || !s.endsWith("]")) {
                System.out.println("IPv6 address must be enclosed in \"[]\"");
                return false;
            }
        }
    }
    s = tok.nextToken();
    if (!s.equals(" ")) {
        System.out.println("Expected \" \", found \"" + s + "\"");
        return false;
    }
    s = tok.nextToken();
    StringTokenizer tok2 = new StringTokenizer(s, ";", true);
    Set principalNames = new HashSet();
    String s2;
    s2 = tok2.nextToken();
    if (s2.equals(";")) {
        System.out.println("In identity \"" + s +
                           "\", expected name, found \";\"");
        return false;
    }
    principalNames.add(s2);
    s2 = tok2.nextToken();
    if (!s2.equals(";"))
        throw new Exception("Can't happen");
    s2 = tok2.nextToken();
    if (s2.equals(";")) {
        System.out.println("In identity \"" + s +
                           "\", expected name, found \";\"");
        return false;
    }
    principalNames.add(s2);
    if (tok2.hasMoreTokens()) {
        System.out.println("In identity \"" + s + "\", too many tokens");
        return false;
    }
    if (principalNames.size() != bogusPrincipals.size()) {
        System.out.println("Wrong number of principal names: " +
                           principalNames.size() + " != " +
                           bogusPrincipals.size());
        return false;
    }
    for (Iterator it = bogusPrincipals.iterator(); it.hasNext(); ) {
        Principal p = (Principal) it.next();
        if (!principalNames.contains(p.getName())) {
            System.out.println("Principal names don't contain \"" +
                               p.getName() + "\"");
            return false;
        }
    }
    s = tok.nextToken();
    if (!s.equals(" ")) {
        System.out.println("Expected \" \", found \"" + s + "\"");
        return false;
    }
    return true;
}
 
源代码11 项目: incubator-iotdb   文件: MTree.java
/**
 * Iterate through MTree to fetch metadata info of all leaf nodes under the given seriesPath
 *
 * @param needLast if false, lastTimeStamp in timeseriesSchemaList will be null
 * @param timeseriesSchemaList List<timeseriesSchema> result: [name, alias, storage group,
 * dataType, encoding, compression, offset, lastTimeStamp]
 */
private void findPath(MNode node, String[] nodes, int idx, String parent,
    List<String[]> timeseriesSchemaList, boolean hasLimit, boolean needLast)
    throws MetadataException {
  if (node instanceof MeasurementMNode && nodes.length <= idx) {
    if (hasLimit) {
      curOffset.set(curOffset.get() + 1);
      if (curOffset.get() < offset.get() || count.get().intValue() == limit.get().intValue()) {
        return;
      }
    }
    String nodeName;
    if (node.getName().contains(TsFileConstant.PATH_SEPARATOR)) {
      nodeName = "\"" + node + "\"";
    } else {
      nodeName = node.getName();
    }
    String nodePath = parent + nodeName;
    String[] tsRow = new String[8];
    tsRow[0] = nodePath;
    tsRow[1] = ((MeasurementMNode) node).getAlias();
    MeasurementSchema measurementSchema = ((MeasurementMNode) node).getSchema();
    tsRow[2] = getStorageGroupName(nodePath);
    tsRow[3] = measurementSchema.getType().toString();
    tsRow[4] = measurementSchema.getEncodingType().toString();
    tsRow[5] = measurementSchema.getCompressor().toString();
    tsRow[6] = String.valueOf(((MeasurementMNode) node).getOffset());
    tsRow[7] = needLast ? String.valueOf(getLastTimeStamp((MeasurementMNode) node)) : null;
    timeseriesSchemaList.add(tsRow);

    if (hasLimit) {
      count.set(count.get() + 1);
    }
  }
  String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes);
  if (!nodeReg.contains(PATH_WILDCARD)) {
    if (node.hasChild(nodeReg)) {
      findPath(node.getChild(nodeReg), nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR,
          timeseriesSchemaList, hasLimit, needLast);
    }
  } else {
    for (MNode child : node.getChildren().values()) {
      if (!Pattern.matches(nodeReg.replace("*", ".*"), child.getName())) {
        continue;
      }
      findPath(child, nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR,
          timeseriesSchemaList, hasLimit, needLast);
    }
  }
}
 
源代码12 项目: bonita-studio   文件: ProjectManifestFactory.java
protected boolean isValidBundleName(String symbolicName) {
    return Pattern.matches("[a-zA-Z0-9\\-\\._]+", symbolicName);
}
 
public boolean isDouble(String str) {
    final String Digits     = "(\\p{Digit}+)";
    final String HexDigits  = "(\\p{XDigit}+)";
    // an exponent is 'e' or 'E' followed by an optionally
    // signed decimal integer.
    final String Exp        = "[eE][+-]?"+Digits;
    final String fpRegex    =
            ("[\\x00-\\x20]*"+ // Optional leading "whitespace"
                    "[+-]?(" +         // Optional sign character
                    "NaN|" +           // "NaN" string
                    "Infinity|" +      // "Infinity" string

                    // A decimal floating-point string representing a finite positive
                    // number without a leading sign has at most five basic pieces:
                    // Digits . Digits ExponentPart FloatTypeSuffix
                    //
                    // Since this method allows integer-only strings as input
                    // in addition to strings of floating-point literals, the
                    // two sub-patterns below are simplifications of the grammar
                    // productions from the Java Language Specification, 2nd
                    // edition, section 3.10.2.

                    // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
                    "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+

                    // . Digits ExponentPart_opt FloatTypeSuffix_opt
                    "(\\.("+Digits+")("+Exp+")?)|"+

                    // Hexadecimal strings
                    "((" +
                    // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
                    "(0[xX]" + HexDigits + "(\\.)?)|" +

                    // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
                    "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +

                    ")[pP][+-]?" + Digits + "))" +
                    "[fFdD]?))" +
                    "[\\x00-\\x20]*");// Optional trailing "whitespace"

    if (Pattern.matches(fpRegex, str)){
        Double.valueOf(str);
        return true;
    } else {
      return false;
    }
}
 
源代码14 项目: PocketEOS-Android   文件: RegexUtil.java
/**
 * 验证日期(年月日)
 *
 * @param birthday 日期,格式:1992-09-03,或1992.09.03
 * @return 验证成功返回true ,验证失败返回false
 */
public static boolean checkBirthday(String birthday) {
    String regex = "[1-9]{4}([-./])\\d{1,2}\\1\\d{1,2}";
    return Pattern.matches(regex, birthday);
}
 
源代码15 项目: SpringBoot-Home   文件: IdCardValidatorUtils.java
/**
 * 18位身份证号码的基本数字和位数验校
 *
 * @param idCard
 * @return
 */
public boolean is18Idcard(String idCard) {
    return Pattern.matches("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([\\d|x|X]{1})$", idCard);
}
 
源代码16 项目: platform   文件: RegexUtils.java
/**
 * 验证空白字符
 *
 * @param blankSpace 空白字符,包括:空格、\t、\n、\r、\f、\x0B
 * @return 验证成功返回true,验证失败返回false
 */
public static boolean checkBlankSpace(String blankSpace) {
    String regex = "\\s+";
    return Pattern.matches(regex, blankSpace);
}
 
源代码17 项目: bird-java   文件: StringHelper.java
/**
 * 验证中文
 * @param chinese 中文字符
 * @return 验证成功返回true,验证失败返回false
 */
public static boolean checkChinese(String chinese) {
    String regex = "^[\u4E00-\u9FA5]+$";
    return Pattern.matches(regex,chinese);
}
 
源代码18 项目: IndexableRecyclerView   文件: PinyinUtil.java
/**
 * Are start with a letter
 *
 * @return if return false, index should be #
 */
static boolean matchingLetter(String inputString) {
    return Pattern.matches(PATTERN_LETTER, inputString);
}
 
源代码19 项目: dragonwell8_jdk   文件: String.java
/**
 * Tells whether or not this string matches the given <a
 * href="../util/regex/Pattern.html#sum">regular expression</a>.
 *
 * <p> An invocation of this method of the form
 * <i>str</i>{@code .matches(}<i>regex</i>{@code )} yields exactly the
 * same result as the expression
 *
 * <blockquote>
 * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#matches(String,CharSequence)
 * matches(<i>regex</i>, <i>str</i>)}
 * </blockquote>
 *
 * @param   regex
 *          the regular expression to which this string is to be matched
 *
 * @return  {@code true} if, and only if, this string matches the
 *          given regular expression
 *
 * @throws  PatternSyntaxException
 *          if the regular expression's syntax is invalid
 *
 * @see java.util.regex.Pattern
 *
 * @since 1.4
 * @spec JSR-51
 */
public boolean matches(String regex) {
    return Pattern.matches(regex, this);
}
 
源代码20 项目: util4j   文件: RegexValidator.java
/**
 * 校验邮箱
 * 
 * @param email
 * @return 校验通过返回true,否则返回false
 */
public static boolean isEmail(String email) {
    return Pattern.matches(REGEX_EMAIL, email);
}