本文整理匯總了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;
}
}
示例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;
}
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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));
}
}
示例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);
}
}
示例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);
}
示例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());
}
示例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;
}
示例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();
}
}
}
}
}
示例13: execute
import java.util.regex.Pattern; //導入方法依賴的package包/類
@Override
public Object execute(Object... args) {
return Pattern.matches((String) args[0], (String) args[1]);
}
示例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);
}
示例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);
}