Java Code Examples for java.util.regex.Pattern#matches()
The following examples show how to use
java.util.regex.Pattern#matches() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WasbCloudStorageParametersValidator.java From cloudbreak with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: ResourceSet.java From zeppelin with Apache License 2.0 | 5 votes |
public ResourceSet filterByClassnameRegex(String regex) { ResourceSet result = new ResourceSet(); for (Resource r : this) { if (Pattern.matches(regex, r.getClassName())) { result.add(r); } } return result; }
Example 3
Source File: SString.java From aion_api with MIT License | 5 votes |
/** * 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); }
Example 4
Source File: ValidatorPattern.java From openzaly with Apache License 2.0 | 5 votes |
/** * 校验邮箱 * * @param email * @return 校验通过返回true,否则返回false */ public static boolean isEmail(String email) { if (email == null) { return false; } return Pattern.matches(REGEX_EMAIL, email); }
Example 5
Source File: JCIFSSpnegoAuthenticationHandler.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
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]); }
Example 6
Source File: Page.java From WebCollector with GNU General Public License v3.0 | 5 votes |
/** * 判断当前Page的Http响应头的Content-Type是否符合正则 * * @param contentTypeRegex * @return */ public boolean matchContentType(String contentTypeRegex) { if (contentTypeRegex == null) { return contentType() == null; } return Pattern.matches(contentTypeRegex, contentType()); }
Example 7
Source File: PCEqTypeTermEvaluator.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
@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; }
Example 8
Source File: JAXWSUtils.java From hottub with GNU General Public License v2.0 | 5 votes |
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; }
Example 9
Source File: ConnectionTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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; }
Example 10
Source File: MTree.java From incubator-iotdb with Apache License 2.0 | 4 votes |
/** * 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); } } }
Example 11
Source File: DBCPPoolAdapter.java From flexy-pool with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected boolean isAcquireTimeoutException(Exception e) { return e.getMessage() != null && Pattern.matches(ACQUIRE_TIMEOUT_MESSAGE, e.getMessage()); }
Example 12
Source File: ProjectManifestFactory.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected boolean isValidBundleName(String symbolicName) { return Pattern.matches("[a-zA-Z0-9\\-\\._]+", symbolicName); }
Example 13
Source File: InterpolatingLookupPaintScaleSetupDialogController.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
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; } }
Example 14
Source File: IdCardValidatorUtils.java From SpringBoot-Home with Apache License 2.0 | 2 votes |
/** * 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); }
Example 15
Source File: RegexUtils.java From platform with Apache License 2.0 | 2 votes |
/** * 验证空白字符 * * @param blankSpace 空白字符,包括:空格、\t、\n、\r、\f、\x0B * @return 验证成功返回true,验证失败返回false */ public static boolean checkBlankSpace(String blankSpace) { String regex = "\\s+"; return Pattern.matches(regex, blankSpace); }
Example 16
Source File: StringHelper.java From bird-java with MIT License | 2 votes |
/** * 验证中文 * @param chinese 中文字符 * @return 验证成功返回true,验证失败返回false */ public static boolean checkChinese(String chinese) { String regex = "^[\u4E00-\u9FA5]+$"; return Pattern.matches(regex,chinese); }
Example 17
Source File: PinyinUtil.java From IndexableRecyclerView with Apache License 2.0 | 2 votes |
/** * Are start with a letter * * @return if return false, index should be # */ static boolean matchingLetter(String inputString) { return Pattern.matches(PATTERN_LETTER, inputString); }
Example 18
Source File: String.java From dragonwell8_jdk with GNU General Public License v2.0 | 2 votes |
/** * 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); }
Example 19
Source File: RegexValidator.java From util4j with Apache License 2.0 | 2 votes |
/** * 校验邮箱 * * @param email * @return 校验通过返回true,否则返回false */ public static boolean isEmail(String email) { return Pattern.matches(REGEX_EMAIL, email); }
Example 20
Source File: RegexUtil.java From PocketEOS-Android with GNU Lesser General Public License v3.0 | 2 votes |
/** * 验证日期(年月日) * * @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); }