本文整理匯總了Java中java.util.regex.Matcher.matches方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.matches方法的具體用法?Java Matcher.matches怎麽用?Java Matcher.matches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.matches方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: marathon_select
import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override public boolean marathon_select(String tab) {
Matcher matcher = CLOSE_PATTERN.matcher(tab);
boolean isCloseTab = matcher.matches();
tab = isCloseTab ? matcher.group(1) : tab;
TabPane tp = (TabPane) node;
ObservableList<Tab> tabs = tp.getTabs();
for (int index = 0; index < tabs.size(); index++) {
String current = getTextForTab(tp, tabs.get(index));
if (tab.equals(current)) {
if (isCloseTab) {
((TabPaneSkin) tp.getSkin()).getBehavior().closeTab(tabs.get(index));
return true;
}
tp.getSelectionModel().select(index);
return true;
}
}
return false;
}
示例2: isPhoneNumberValid
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* 判斷電話號碼是否有效
*
* @param phoneNumber
* @return true 有效 / false 無效
*/
public static boolean isPhoneNumberValid(String phoneNumber) {
boolean isValid = false;
String expression = "((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1}\\d{1}-?\\d{8}$)|(^0[3-9] {1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-? \\d{7,8}-(\\d{1,4})$))";
CharSequence inputStr = phoneNumber;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
示例3: parse
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static GeoPoint parse(String str) {
String description;
Matcher m = WITH_DESCRIPTION_PATTERN.matcher(str);
if (m.matches()) {
description = m.group(1).trim();
str = m.group(2).trim();
} else {
description = null;
}
String[] parts = str.split(",");
if (parts.length < 2) {
throw new MemgraphException("Too few parts to GeoPoint string. Expected at least 2 found " + parts.length + " for string: " + str);
}
if (parts.length >= 4) {
throw new MemgraphException("Too many parts to GeoPoint string. Expected less than or equal to 3 found " + parts.length + " for string: " + str);
}
double latitude = parsePart(parts[0]);
double longitude = parsePart(parts[1]);
Double altitude = null;
if (parts.length >= 3) {
altitude = Double.parseDouble(parts[2]);
}
return new GeoPoint(latitude, longitude, altitude, description);
}
示例4: apply
import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
boolean apply(IXulDataSelectContext dataCtx, ArrayList<XulDataNode> ctx) {
if (_pattern == null) {
for (int i = ctx.size() - 1; i >= 0; i--) {
if (!_content.equals(ctx.get(i).getValue())) {
ctx.remove(i);
}
}
} else {
for (int i = ctx.size() - 1; i >= 0; i--) {
Matcher matcher = _pattern.matcher(ctx.get(i).getValue());
if (matcher == null || !matcher.matches()) {
ctx.remove(i);
}
}
}
return true;
}
示例5: isHKPhoneLegal
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* 香港手機號碼8位數,5|6|8|9開頭+7位任意數
*/
public static boolean isHKPhoneLegal(String str) throws PatternSyntaxException {
String regExp = "^(5|6|8|9)\\d{7}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(str);
return m.matches();
}
示例6: match
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static boolean match(String text, String regex) {
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(text);
if (matcher.matches()) {
return true;
}
return false;
}
示例7: getGID
import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?zizki\\.com/([a-zA-Z0-9\\-_]+).*$");
Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) {
throw new MalformedURLException("Expected URL format: http://www.zizki.com/author/albumname, got: " + url);
}
return m.group(m.groupCount());
}
示例8: getGraphPathWithVersion
import java.util.regex.Matcher; //導入方法依賴的package包/類
private String getGraphPathWithVersion() {
Matcher matcher = versionPattern.matcher(this.graphPath);
if (matcher.matches()) {
return this.graphPath;
}
return String.format("%s/%s", this.version, this.graphPath);
}
示例9: canRip
import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public boolean canRip(URL url) {
String url_name = url.toExternalForm();
if (explicit_domains_1.contains(url_name.split("/")[2])) {
Pattern pa = Pattern.compile("(?:https?://)?(?:www\\.)?[a-z1-9-]*\\.[a-z1-9]*/album/([a-zA-Z1-9]*)/?$");
Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) {
return true;
}
}
return false;
}
示例10: isTextValid
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static boolean isTextValid(String aText, boolean canBeNull){
if (!canBeNull && (aText == null || aText.trim().length() == 0)){
return(false);
}
if (canBeNull && (aText == null || aText.trim().length() == 0)){
return(true);
}
String checkText = aText.toUpperCase();
try {
Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL + Pattern.CASE_INSENSITIVE + Pattern.UNIX_LINES);
Matcher matcher = pattern.matcher(checkText);
if (matcher.matches()) {
return(false);
}
Pattern patternHex = Pattern.compile(hexPatternStr, Pattern.DOTALL + Pattern.CASE_INSENSITIVE + Pattern.UNIX_LINES);
Matcher matcherHex = patternHex.matcher(checkText);
if (matcherHex.matches()) {
return(false);
}
}
catch (Exception e) {
Debug.info("Threw exception " + e.getMessage());
return(false);
}
return(true);
}
示例11: upsLength
import java.util.regex.Matcher; //導入方法依賴的package包/類
private static int upsLength(String path) {
Matcher m = goUpPattern.matcher(path);
if(m.matches()) {
return m.group(1).length();
} else {
return 0;
}
}
示例12: getGID
import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wm.]*dribbble\\.com/([a-zA-Z0-9]+).*$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
throw new MalformedURLException("Expected dribbble.com URL format: " +
"dribbble.com/albumid - got " + url + "instead");
}
示例13: isEmail
import java.util.regex.Matcher; //導入方法依賴的package包/類
public boolean isEmail(String email) {
String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
Pattern p = Pattern.compile(str);
Matcher m = p.matcher(email);
return m.matches();
}
示例14: getDarkHighlightColor
import java.util.regex.Matcher; //導入方法依賴的package包/類
@ColorInt
public static int getDarkHighlightColor(String className) {
Matcher matcher = HIGHLIGHT_CLASS_PATTERN.matcher(className);
int classNumber = 0;
if (matcher.matches()) {
classNumber = Integer.parseInt(matcher.group(1));
}
return highlightDarkColorMap.get(classNumber);
}
示例15: getFrequencyFromString
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Converts the frequency string to a double value.
*
* @param freq
* @return
*/
private double getFrequencyFromString(String freq)
{
double f = 1.0;
if (freq == null || freq.length() == 0) {
return 1.0;
}
Matcher matcher = frequencyPattern.matcher(freq);
if (matcher.matches()) {
String fractionalPart = matcher.group(2);
if (fractionalPart == null || fractionalPart.length() == 0) {
fractionalPart = "0";
}
f =
Double.parseDouble(matcher.group(1)) + Double.parseDouble(fractionalPart)
/ Math.pow(10, fractionalPart.length());
f /= 100.0;
} else {
matcher = frequencyFractionPattern.matcher(freq);
if (matcher.matches()) {
f = Double.parseDouble(matcher.group(1)) / Double.parseDouble(matcher.group(2));
} else {
if (freq.equalsIgnoreCase("very rare")) {
f = 0.01;
} else if (freq.equalsIgnoreCase("rare")) {
f = 0.05;
} else if (freq.equalsIgnoreCase("occasional")) {
f = 0.075;
} else if (freq.equalsIgnoreCase("frequent")) {
f = 0.33;
} else if (freq.equalsIgnoreCase("typical")) {
f = 0.50;
} else if (freq.equalsIgnoreCase("common")) {
f = 0.75;
} else if (freq.equalsIgnoreCase("hallmark")) {
f = 0.90;
} else if (freq.equalsIgnoreCase("obligate")) {
f = 1;
} else {
logger.info("Unknown frequency identifier: {}", freq);
}
}
}
return f;
}