本文整理匯總了Java中java.util.regex.Pattern類的典型用法代碼示例。如果您正苦於以下問題:Java Pattern類的具體用法?Java Pattern怎麽用?Java Pattern使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Pattern類屬於java.util.regex包,在下文中一共展示了Pattern類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: a
import java.util.regex.Pattern; //導入依賴的package包/類
public static int a(Set<String> set) {
if (set == null || set.isEmpty()) {
return 0;
}
if (set.size() > 100) {
return d.g;
}
for (String str : set) {
if (str == null) {
return d.e;
}
if (str.getBytes().length > 40) {
return d.f;
}
if (!Pattern.compile(z[1]).matcher(str).matches()) {
return d.e;
}
}
return 0;
}
示例2: decode_set_vlan_priority
import java.util.regex.Pattern; //導入依賴的package包/類
/**
* Parse set_vlan_pcp actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. Data with a leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetVlanPcp decode_set_vlan_priority(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
VlanPcp prior = VlanPcp.of(get_byte(n.group(1)));
OFActionSetVlanPcp.Builder ab = OFFactories.getFactory(version).actions().buildSetVlanPcp();
ab.setVlanPcp(prior);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid VLAN priority in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例3: updateFromPreferences
import java.util.regex.Pattern; //導入依賴的package包/類
public void updateFromPreferences(SharedPreferences prefs) {
screenOnPattern = null;
screenOnItemName = prefs.getString("pref_screen_item", "");
enabled = prefs.getBoolean("pref_screen_enabled", false);
keepOn = prefs.getBoolean("pref_screen_stay_enabled", false);
String onRegexpStr = prefs.getString("pref_screen_on_regex", "");
if (!onRegexpStr.isEmpty()) {
try {
screenOnPattern = Pattern.compile(onRegexpStr);
} catch (PatternSyntaxException e) {
// is handled in the preferences
}
}
mServerConnection.subscribeItems(this, screenOnItemName);
}
示例4: getStyledText
import java.util.regex.Pattern; //導入依賴的package包/類
/**
* This returns the label styled text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object getStyledText ( Object object )
{
Pattern labelValue = ( (AknProxy)object ).getPattern ();
String label = labelValue == null ? null : labelValue.toString ();
StyledString styledLabel = new StyledString ();
if ( label == null || label.length () == 0 )
{
styledLabel.append ( getString ( "_UI_AknProxy_type" ), StyledString.Style.QUALIFIER_STYLER ); //$NON-NLS-1$
}
else
{
styledLabel.append ( getString ( "_UI_AknProxy_type" ), StyledString.Style.QUALIFIER_STYLER ).append ( " " + label ); //$NON-NLS-1$ //$NON-NLS-2$
}
return styledLabel;
}
示例5: buildPopup
import java.util.regex.Pattern; //導入依賴的package包/類
@NbBundle.Messages("PARTIAL_RESULT=<Result is incomplete, some indices are processed>")
private void buildPopup() {
pattern = Pattern.compile(getCompletionPrefix() + ".+"); //NOI18N
int entryindex = 0;
for (String completion : completions) {
// check if match
Matcher matcher = pattern.matcher(completion);
if (matcher.matches()) {
if (!completionListModel.contains(completion)) {
completionListModel.add(entryindex,
completion);
}
entryindex++;
} else {
completionListModel.removeElement(completion);
}
}
completionListModel.removeElement(Bundle.PARTIAL_RESULT());
if (partial) {
completionListModel.addElement(Bundle.PARTIAL_RESULT());
}
}
示例6: fromString
import java.util.regex.Pattern; //導入依賴的package包/類
public static Item fromString(String str) {
String[] b = str.trim().replace(' ', '_').replace("minecraft:", "").split(":");
int id = 0;
int meta = 0;
Pattern integerPattern = Pattern.compile("^[1-9]\\d*$");
if (integerPattern.matcher(b[0]).matches()) {
id = Integer.valueOf(b[0]);
} else {
try {
id = Item.class.getField(b[0].toUpperCase()).getInt(null);
} catch (Exception ignore) {
}
}
id = id & 0xFFFF;
if (b.length != 1) meta = Integer.valueOf(b[1]) & 0xFFFF;
return get(id, meta);
}
示例7: detectFilter
import java.util.regex.Pattern; //導入依賴的package包/類
private Filter detectFilter(List filters) {
Set<Class> filterClasses = new HashSet<Class>();
for (Object filter : filters) {
filterClasses.add(filter.getClass());
}
if (filterClasses.size() > 1) {
throw new IllegalArgumentException("Inconsistent filters: " + filters + ". Only one type [line,name,tag] can be used at once.");
}
Class<?> typeOfFilter = filters.get(0).getClass();
if (String.class.isAssignableFrom(typeOfFilter)) {
return new TagFilter(filters);
} else if (Number.class.isAssignableFrom(typeOfFilter)) {
return new LineFilter(filters);
} else if (Pattern.class.isAssignableFrom(typeOfFilter)) {
return new PatternFilter(filters);
} else {
throw new RuntimeException("Could not create filter method for unknown filter of type: " + typeOfFilter);
}
}
示例8: verifyResponse
import java.util.regex.Pattern; //導入依賴的package包/類
@Test
public void verifyResponse() {
final Response resp = this.googleAccountsService.getResponse("ticketId");
assertEquals(resp.getResponseType(), DefaultResponse.ResponseType.POST);
final String response = resp.getAttributes().get(SamlProtocolConstants.PARAMETER_SAML_RESPONSE);
assertNotNull(response);
assertTrue(response.contains("NotOnOrAfter"));
final Pattern pattern = Pattern.compile("NotOnOrAfter\\s*=\\s*\"(.+Z)\"");
final Matcher matcher = pattern.matcher(response);
final DateTime now = DateTime.parse(new ISOStandardDateFormat().getCurrentDateAndTime());
while (matcher.find()) {
final String onOrAfter = matcher.group(1);
final DateTime dt = DateTime.parse(onOrAfter);
assertTrue(dt.isAfter(now));
}
assertTrue(resp.getAttributes().containsKey(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE));
}
示例9: getDataObjectExchangeItem
import java.util.regex.Pattern; //導入依賴的package包/類
/** {@inheritDoc}
*/
public IExchangeItem getDataObjectExchangeItem(String exchangeItemID) {
String[] parts = Pattern.compile(idSeparator, Pattern.LITERAL).split(exchangeItemID);
if (parts.length != 2) {
throw new RuntimeException("Invalid exchangeItemID " + exchangeItemID );
}
String location = parts[0];
String quantity = parts[1];
// Get the single time series based on location and quantity
TimeSeriesSet myTimeSeriesSet = this.timeSeriesSet.getOnQuantity(quantity)
.getOnLocation(location);
Iterator<TimeSeries> iterator = myTimeSeriesSet.iterator();
if (!iterator.hasNext()) {
throw new RuntimeException("No time series found for " + exchangeItemID);
}
TimeSeries timeSeries = iterator.next();
if (iterator.hasNext()) {
throw new RuntimeException("Time series is not uniquely defined for " + exchangeItemID);
}
return timeSeries;
}
示例10: filterMedicines
import java.util.regex.Pattern; //導入依賴的package包/類
public static List<Medicine> filterMedicines(String searchValue, List<Medicine> medicines, boolean exactMatches) {
List<Medicine> filteredMedicines = new ArrayList<>();
if (TextUtils.isEmpty(searchValue)) {
filteredMedicines = medicines;
}
if (CollectionUtils.isNotEmpty(medicines) && !TextUtils.isEmpty(searchValue)) {
String patternRegex = prepareRegexPattern(searchValue, exactMatches);
Pattern pattern = Pattern.compile(patternRegex);
Matcher matcher;
for (Medicine medicine : medicines) {
matcher = pattern.matcher(medicine.getName());
if (matcher.matches()) {
filteredMedicines.add(medicine);
}
}
}
return filteredMedicines;
}
示例11: replaceSpecialtyStr
import java.util.regex.Pattern; //導入依賴的package包/類
public static String replaceSpecialtyStr(String str, String pattern, String replace)
{
if (isBlankOrNull(pattern))
pattern = "\\s*|\t|\r|\n";//去除字符串中空格、換行、製表
if (isBlankOrNull(replace))
replace = "";
return Pattern.compile(pattern).matcher(str).replaceAll(replace);
}
示例12: updateSmartSource
import java.util.regex.Pattern; //導入依賴的package包/類
@Override
public boolean updateSmartSource(String oldString, String newString) {
String smartValue = textValue.getSmartValue();
if (smartValue.indexOf(oldString) != -1 || Pattern.compile(oldString).matcher(smartValue).find()) {
textValue.setSmartValue(smartValue.replaceAll(oldString, newString));
this.hasChanged = true;
}
boolean updated = super.updateSmartSource(oldString, newString);
return updated || this.hasChanged;
}
示例13: matchBytecode
import java.util.regex.Pattern; //導入依賴的package包/類
/**
* Check if bytecode:advice combination is matched by the provided pattern.
* @param pattern
* @param b
*/
private static void matchBytecode(Pattern pattern, VMABytecodes b, boolean[] state, boolean setting) {
final String name = b.name();
if (pattern.matcher(name).matches() || pattern.matcher(name + ":AB").matches()) {
state[0] = setting;
state[1] = setting;
} else if (pattern.matcher(name + ":B").matches()) {
state[0] = setting;
} else if (pattern.matcher(name + ":A").matches()) {
state[1] = setting;
}
}
示例14: Rule
import java.util.regex.Pattern; //導入依賴的package包/類
Rule(int numOfComponents, String format, String match, String fromPattern,
String toPattern, boolean repeat) {
isDefault = false;
this.numOfComponents = numOfComponents;
this.format = format;
this.match = match == null ? null : Pattern.compile(match);
this.fromPattern =
fromPattern == null ? null : Pattern.compile(fromPattern);
this.toPattern = toPattern;
this.repeat = repeat;
}
示例15: isEnglish
import java.util.regex.Pattern; //導入依賴的package包/類
/**
* 是否為英文
*
* @param checkValue
* @return boolean
*/
public static boolean isEnglish(String checkValue) {
String el = "^[A-Za-z]+$";
Pattern p = Pattern.compile(el);
Matcher m = p.matcher(checkValue);
return m.matches();
}