当前位置: 首页>>代码示例>>Java>>正文


Java Pattern.matches方法代码示例

本文整理汇总了Java中java.util.regex.Pattern.matches方法的典型用法代码示例。如果您正苦于以下问题:Java Pattern.matches方法的具体用法?Java Pattern.matches怎么用?Java Pattern.matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.regex.Pattern的用法示例。


在下文中一共展示了Pattern.matches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureByName

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 *  Attempts to find the configured topicName in the list of topics for
 *  the current account. If successful, configures the writer and returns
 *  true. If unsucessful, attempts to create the topic and configure as
 *  above.
 */
private boolean configureByName()
{
    if (! Pattern.matches(SNSConstants.TOPIC_NAME_REGEX, config.topicName))
    {
        return initializationFailure("invalid topic name: " + config.topicName, null);
    }

    topicArn = retrieveAllTopicsByName().get(config.topicName);
    if (topicArn != null)
    {
        return true;
    }
    else
    {
        LogLog.debug("creating SNS topic: " + config.topicName);
        CreateTopicResult response = client.createTopic(config.topicName);
        topicArn = response.getTopicArn();
        return true;
    }
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:27,代码来源:SNSLogWriter.java

示例2: getNumCores

import java.util.regex.Pattern; //导入方法依赖的package包/类
public static int getNumCores() {
    class CpuFilter implements FileFilter {
        @Override
        public boolean accept(File pathname) {
            if(Pattern.matches("cpu[0-9]", pathname.getName())) {
                return true;
            }
            return false;
        }      
    }
    try {
        File dir = new File("/sys/devices/system/cpu/");
        File[] files = dir.listFiles(new CpuFilter());
        return files.length;
    } catch(Exception e) {
        e.printStackTrace();
        return 1;
    }
}
 
开发者ID:HuaDanJson,项目名称:FaceAI_Android,代码行数:20,代码来源:FaceUtil.java

示例3: match

import java.util.regex.Pattern; //导入方法依赖的package包/类
private static boolean match(String pattern, String name)
{
	StringBuilder regex = new StringBuilder();

	while (pattern.length() > 0) {
		int starPos = pattern.indexOf('*');
		if (starPos < 0) {
			regex.append(Pattern.quote(pattern));
			break;
		}
		else {
			String beforeStar = pattern.substring(0, starPos);
			String afterStar = pattern.substring(starPos + 1);

			regex.append(Pattern.quote(beforeStar));
			regex.append(".*");
			pattern = afterStar;
		}
	}

	return Pattern.matches(regex.toString(), name);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:23,代码来源:BenchmarkRunner.java

示例4: parseNumber

import java.util.regex.Pattern; //导入方法依赖的package包/类
public static String parseNumber(String number) {
	if (!Pattern.matches(PHONE_NUMBER_REGEX, number)) {
		LOGGER.error("invalid phone number. {}", number);
		return null;
	}
	if (Pattern.matches(SHORT_PHONE_NUMBER_REGEX, number)) {
		number = "+86" + number;
	}
	try {
		PhoneNumber phoneNumber = PN_Util.parse(number, "CH");
		if (PN_Util.isValidNumber(phoneNumber)) {
			return String.valueOf(phoneNumber.getNationalNumber());
		}
		LOGGER.error("invalid phone number. {}", number);
		return null;
	} catch (NumberParseException e) {
		LOGGER.error("invalid phone number. {}", number);
		return null;
	}
}
 
开发者ID:JK-River,项目名称:RobotServer,代码行数:21,代码来源:PhoneNumberUtils.java

示例5: isNewEnergyType

import java.util.regex.Pattern; //导入方法依赖的package包/类
static boolean isNewEnergyType(String number) {
    if (number != null && number.length() > 2) {
        final int size = 8 - number.length();
        for (int i = 0; i < size; i++) {
            number += "0";
        }
        if (Pattern.matches("\\w[A-Z][0-9DF][0-9A-Z]\\d{3}[0-9DF]", number)) {
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
开发者ID:parkingwang,项目名称:vehicle-keyboard-android,代码行数:16,代码来源:Texts.java

示例6: search

import java.util.regex.Pattern; //导入方法依赖的package包/类
private boolean search(String bulk) {
	String a = textField.getText();
	String b = bulk;
	if (regex.isSelected())
		return Pattern.matches(a, b);
	if (wholew.isSelected())
		a = " " + a + " ";
	if (!mcase.isSelected()) {
		a = a.toLowerCase();
		b = b.toLowerCase();
	}
	if (b.contains(a))
		return true;
	return false;
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:16,代码来源:FindAllBox.java

示例7: unifiedNumericToBigInteger

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * @param number should be in form '0x34fabd34....'
 * @return String
 */
public static BigInteger unifiedNumericToBigInteger(String number) {

    boolean match = Pattern.matches("0[xX][0-9a-fA-F]+", number);
    if (!match)
        return (new BigInteger(number));
    else{
        number = number.substring(2);
        number = number.length() % 2 != 0 ? "0".concat(number) : number;
        byte[] numberBytes = Hex.decode(number);
        return (new BigInteger(1, numberBytes));
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:17,代码来源:Utils.java

示例8: verifyFieldValueRegex

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * Verify the field value matches the specified java regular expression
 *
 * @param expectedValueRegex a java regular expression
 * @param row the field row starting at 0
 * @param column the field column starting at 0
 */
@PublicAtsApi
public void verifyFieldValueRegex( String expectedValueRegex, int row, int column ) {

    String actualValue = getFieldValue(row, column);

    if (!Pattern.matches(expectedValueRegex, actualValue)) {
        throw new VerifyEqualityException(expectedValueRegex, actualValue, this);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:17,代码来源:HiddenHtmlTable.java

示例9: checkPostcode

import java.util.regex.Pattern; //导入方法依赖的package包/类
public static boolean checkPostcode(String postcode) {
    String regex = "[1-9]\\d{5}";
    return Pattern.matches(regex, postcode);
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:5,代码来源:VerificationUtils.java

示例10: isUsnValid

import java.util.regex.Pattern; //导入方法依赖的package包/类
boolean isUsnValid(CharSequence s) {
    // TODO: create regExp particular to USN
    return !Pattern.matches("^(a-z|A-Z|0-9)*[^#$%^&*()' /+_-]*$", s.toString());
}
 
开发者ID:rumaan,项目名称:AcademApp,代码行数:5,代码来源:UserDetailsActivity.java

示例11: getNativeInputMethodInfo

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * Returns a string with information about the current input method server, or null.
 * On both Linux & SunOS, the value of environment variable XMODIFIERS is
 * returned if set. Otherwise, on SunOS, $HOME/.dtprofile will be parsed
 * to find out the language service engine (atok or wnn) since there is
 * no API in Xlib which returns the information of native
 * IM server or language service and we want to try our best to return as much
 * information as possible.
 *
 * Note: This method could return null on Linux if XMODIFIERS is not set properly or
 * if any IOException is thrown.
 * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS,
 * atok12setup(1) and wnn6setup(1) for the information written to
 * $HOME/.dtprofile when you run these two commands.
 *
 */
public String getNativeInputMethodInfo() {
    String xmodifiers = System.getenv("XMODIFIERS");
    String imInfo = null;

    // If XMODIFIERS is set, return the value
    if (xmodifiers != null) {
        int imIndex = xmodifiers.indexOf("@im=");
        if (imIndex != -1) {
            imInfo = xmodifiers.substring(imIndex + 4);
        }
    } else if (System.getProperty("os.name").startsWith("SunOS")) {
        File dtprofile = new File(System.getProperty("user.home") +
                                  "/.dtprofile");
        String languageEngineInfo = null;
        try {
            BufferedReader br = new BufferedReader(new FileReader(dtprofile));
            String line = null;

            while ( languageEngineInfo == null && (line = br.readLine()) != null) {
                if (line.contains("atok") || line.contains("wnn")) {
                    StringTokenizer tokens =  new StringTokenizer(line);
                    while (tokens.hasMoreTokens()) {
                        String token = tokens.nextToken();
                        if (Pattern.matches("atok.*setup", token) ||
                            Pattern.matches("wnn.*setup", token)){
                            languageEngineInfo = token.substring(0, token.indexOf("setup"));
                            break;
                        }
                    }
                }
            }

            br.close();
        } catch(IOException ioex) {
            // Since this method is provided for internal testing only,
            // we dump the stack trace for the ease of debugging.
            ioex.printStackTrace();
        }

        imInfo = "htt " + languageEngineInfo;
    }

    return imInfo;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:61,代码来源:X11InputMethod.java

示例12: listCustomizations

import java.util.regex.Pattern; //导入方法依赖的package包/类
/** This method will list the customizations added to a code generated file.
 * @param file the code generated file.
 * @param writer the customizations will be written to this writer.
 * @param customizationFilter the customizations will be filtered based on this paramter. If no value is passed, then all the customizations will be listed.
 * @throws IOException if any IO error occurs.
 * @throws SourceDecomposerException if the file is malformed or if it cannot be decomposed.
 */
public static void listCustomizations(File file, BufferedWriter writer, String customizationFilter)
throws IOException, SourceDecomposerException {
    System.out.println("Processing file... " + file);
    SourceDecomposer sd = new SourceDecomposer(new BufferedReader(new FileReader(file)));
    Collection elements = sd.getCollection();
    boolean headerWritten = false;
    if (elements != null) {
        for (Iterator itr = elements.iterator(); itr.hasNext();) {
            Object obj = itr.next();
            if (obj instanceof SourceDecomposer.GuardedBorder) {
                SourceDecomposer.GuardedBorder gb = (SourceDecomposer.GuardedBorder) obj;
                
                // Check the name of the customization block against the filter
                if (customizationFilter != null && customizationFilter.length() > 0) {
                    try {
                        // Ignore this customization, if it does not match the filter
                        if (!Pattern.matches(customizationFilter, gb.getKey()))
                            continue;
                    } catch (PatternSyntaxException e) {
                        e.printStackTrace();
                        throw new IllegalArgumentException("Invalid customizationFilter passed: " + customizationFilter);
                    }
                }
                
                // Strip the borders from the contents
                StringHelper.Line line = null;
                StringBuffer buf = new StringBuffer();
                PushbackReader reader = new PushbackReader(new StringReader(gb.getContents()));
                while ((line = StringHelper.readLine(reader)) != null) {
                    if (line.getContents().indexOf(SourceDecomposer.FIRST) < 0 && line.getContents().indexOf(SourceDecomposer.LAST) < 0)
                        buf.append(line);
                }
                String contents = buf.toString().trim();
                
                // Only write if the contents are not empty
                if (contents.length() > 0) {
                    if (!headerWritten) {
                        writer.write("===============================================================================\n");
                        writer.write(file.getPath());
                        writer.write("\n===============================================================================\n");
                        headerWritten = true;
                    }
                    writer.write("* " + gb.getKey() + '\n');
                    writer.write(contents);
                    writer.write("\n\n");
                    writer.flush();
                }
            }
        }
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:59,代码来源:SourceDecomposerUtils.java

示例13: execute

import java.util.regex.Pattern; //导入方法依赖的package包/类
@Override
public Object execute(Object... args) {
  return Pattern.matches((String) args[0], (String) args[1]);
}
 
开发者ID:srinipunuru,项目名称:samza-sql-tools,代码行数:5,代码来源:RegexMatchUdf.java

示例14: isIPAddr

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * 校验IP地址
 * 
 * @param ipAddr
 * @return
 */
public static boolean isIPAddr(String ipAddr) {
    return Pattern.matches(REGEX_IP_ADDR, ipAddr);
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:10,代码来源:RegexValidator.java

示例15: isMatch

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * 判断是否匹配正则
 *
 * @param regex 正则表达式
 * @param input 要匹配的字符串
 * @return {@code true}: 匹配<br>{@code false}: 不匹配
 */
public static boolean isMatch(String regex, CharSequence input) {
    return input != null && input.length() > 0 && Pattern.matches(regex, input);
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:11,代码来源:RegexUtils.java


注:本文中的java.util.regex.Pattern.matches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。