本文整理汇总了Java中java.util.regex.PatternSyntaxException类的典型用法代码示例。如果您正苦于以下问题:Java PatternSyntaxException类的具体用法?Java PatternSyntaxException怎么用?Java PatternSyntaxException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PatternSyntaxException类属于java.util.regex包,在下文中一共展示了PatternSyntaxException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidPetName
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
public boolean isValidPetName(String name)
{
boolean result = true;
if (!isAlphaNumeric(name))
{
return result;
}
Pattern pattern;
try
{
pattern = Pattern.compile(Config.PET_NAME_TEMPLATE);
}
catch (PatternSyntaxException e) // case of illegal pattern
{
LOGGER.warning(getClass().getSimpleName() + ": Pet name pattern of config is wrong!");
pattern = Pattern.compile(".*");
}
final Matcher regexp = pattern.matcher(name);
if (!regexp.matches())
{
result = false;
}
return result;
}
示例2: uploadSkipRegexFieldDidChange
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
public void uploadSkipRegexFieldDidChange(NSNotification sender) {
String value = this.uploadSkipRegexField.string().trim();
if(StringUtils.EMPTY.equals(value)) {
preferences.setProperty("queue.upload.skip.enable", false);
preferences.setProperty("queue.upload.skip.regex", value);
this.uploadSkipButton.setState(NSCell.NSOffState);
}
try {
Pattern compiled = Pattern.compile(value);
preferences.setProperty("queue.upload.skip.regex",
compiled.pattern());
this.mark(this.uploadSkipRegexField.textStorage(), null);
}
catch(PatternSyntaxException e) {
this.mark(this.uploadSkipRegexField.textStorage(), e);
}
}
示例3: compareBranches
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
protected int compareBranches() {
String val1 = ((StringNode)left).getValue();
String val2 = ((StringNode)right).getValue();
int val2Len = val2.length();
if (val2Len > 1 && val2.charAt(0) == '/' &&
val2.charAt(val2Len - 1) == '/') {
// Treat as a regular expression
String expr = val2.substring(1, val2Len - 1);
try {
Pattern pattern = Pattern.compile(expr);
// Regular expressions will only ever be used with EqualNode
// so return zero for equal and non-zero for not equal
if (pattern.matcher(val1).find()) {
return 0;
} else {
return -1;
}
} catch (PatternSyntaxException pse) {
ssiMediator.log("Invalid expression: " + expr, pse);
return 0;
}
}
return val1.compareTo(val2);
}
示例4: isValidName
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
private static boolean isValidName(String text)
{
boolean result = true;
String test = text;
Pattern pattern;
try
{
pattern = Pattern.compile(Config.CNAME_TEMPLATE);
}
catch(PatternSyntaxException e)
{
_log.warning("ERROR : Character name pattern of config is wrong!");
pattern = Pattern.compile(".*");
}
Matcher regexp = pattern.matcher(test);
if(!regexp.matches())
result = false;
return result;
}
示例5: isValidName
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
private boolean isValidName(String text)
{
boolean result = true;
String test = text;
Pattern pattern;
try
{
pattern = Pattern.compile(Config.CNAME_TEMPLATE);
}
catch (PatternSyntaxException e) // case of illegal pattern
{
_log.warning("ERROR : Character name pattern of config is wrong!");
pattern = Pattern.compile(".*");
}
Matcher regexp = pattern.matcher(test);
if (!regexp.matches())
{
result = false;
}
return result;
}
示例6: compileRegexpPattern
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
/**
* Tries to compile the regular expression pattern, thus checking its
* validity. In case of success, the compiled pattern is stored to {@link #textPattern},
* otherwise the field is set to {@code null}.
*
* <p>Actually, this method defines a pattern used in searching, i.e. it
* defines behaviour of the searching. It should be the same as behavior of
* the Find action (Ctrl+F) in the Editor to avoid any confusions (see Bug
* #175101). Hence, this implementation should specify default flags in the
* call of the method {@link Pattern#compile(java.lang.String, int)
* java.util.regex.Pattern.compile(String regex, int flags)} that are the
* same as in the implementation of the Find action (i.e in the method {@code getFinder}
* of the class {@code org.netbeans.modules.editor.lib2.search.DocumentFinder}).
* </p>
*
* @return {@code true} if the regexp pattern expression was valid; {@code false}
* otherwise
*/
private static Pattern compileRegexpPattern(SearchPattern sp)
throws PatternSyntaxException {
assert sp != null;
assert sp.getSearchExpression() != null;
assert sp.isRegExp();
boolean multiline = canBeMultilinePattern(sp.getSearchExpression());
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, " - textPatternExpr = \"{0}{1}",
new Object[]{sp.getSearchExpression(), '"'}); //NOI18N
}
int flags = 0;
if (!sp.isMatchCase()) {
flags |= Pattern.CASE_INSENSITIVE;
flags |= Pattern.UNICODE_CASE;
}
flags |= Pattern.MULTILINE; // #175101
return Pattern.compile(sp.getSearchExpression(), flags);
}
示例7: testTriggersEventPatternIncorrect
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
public static void testTriggersEventPatternIncorrect(KnowledgeBaseType type) {
Engine engine = null;
try {
engine = ScriptTestUtils.startWithKnowledgeBase(type, "triggers_event_pattern_incorrect");
fail("Expected pattern syntax exception");
} catch (SpongeException e) {
if (ExceptionUtils.indexOfThrowable(e, PatternSyntaxException.class) < 0) {
throw e;
}
} finally {
if (engine != null) {
engine.shutdown();
}
}
}
示例8: updateFileNamePatternColor
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
/**
* Sets proper color of file pattern.
*/
private void updateFileNamePatternColor() {
boolean wasInvalid = patternValid;
String pattern = getFileNamePattern();
if (pattern == null || pattern.isEmpty()) {
patternValid = true;
} else {
try {
Pattern p = RegexpUtil.makeFileNamePattern(
SearchScopeOptions.create(getFileNamePattern(), regexp));
if (p == null) {
patternValid = false;
} else {
patternValid = true;
}
} catch (PatternSyntaxException e) {
patternValid = false;
}
}
if (patternValid != wasInvalid && !isAllFilesInfoDisplayed()) {
fileNamePatternEditor.setForeground(
patternValid ? defaultColor : UiUtils.getErrorTextColor());
}
}
示例9: getMatchinIgnoreParterns
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
public static List<String> getMatchinIgnoreParterns(List<String> patterns, String value, boolean onlyFirstMatch) {
List<String> ret = new ArrayList<String>();
if(patterns == null) return ret;
for (Iterator<String> i = patterns.iterator(); i.hasNext();) {
try {
// may contain shell patterns (almost identical to RegExp)
String patternString = i.next();
String shellPatternString = regExpToFilePatterns(patternString);
Pattern pattern = Pattern.compile(shellPatternString);
if (pattern.matcher(value).matches()) {
ret.add(patternString);
if(onlyFirstMatch) {
return ret;
}
}
} catch (PatternSyntaxException e) {
// it's difference between shell and regexp
// or user error (set invalid property), rethrow?
Subversion.LOG.log(Level.INFO, null, e);
}
}
return ret;
}
示例10: scan
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
/**
* Scan a JavaScript regexp string returning a Java safe regex string.
*
* @param string
* JavaScript regexp string.
* @return Java safe regex string.
*/
public static RegExpScanner scan(final String string) {
final RegExpScanner scanner = new RegExpScanner(string);
try {
scanner.disjunction();
} catch (final Exception e) {
throw new PatternSyntaxException(e.getMessage(), string, scanner.position);
}
scanner.processForwardReferences();
// Throw syntax error unless we parsed the entire JavaScript regexp without syntax errors
if (scanner.position != string.length()) {
final String p = scanner.getStringBuilder().toString();
throw new PatternSyntaxException(string, p, p.length() + 1);
}
return scanner;
}
示例11: documentChanged
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
private void documentChanged() {
if (suppressEvents) {
return;
}
String pat = namePattern.getText().trim();
if (!"".equals(pat)) {
// check the pattern is OK
try {
Pattern p = Pattern.compile(pat);
} catch (PatternSyntaxException ex) {
namePattern.setBackground(errorBkColor);
return;
}
namePattern.setBackground(defaultBkColor);
}
prefs.put(ConstantNameHint.PREF_CONSTANT_NAME_PATTERN, pat);
}
示例12: parseNormalDiff
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
private static Difference[] parseNormalDiff(Reader in) throws IOException {
Pattern normRegexp;
try {
normRegexp = Pattern.compile(CmdlineDiffProvider.DIFF_REGEXP);
} catch (PatternSyntaxException rsex) {
normRegexp = null;
}
StringBuffer firstText = new StringBuffer();
StringBuffer secondText = new StringBuffer();
BufferedReader br = new BufferedReader(in);
List<Difference> diffs = new ArrayList<Difference>();
String line;
while ((line = br.readLine()) != null) {
CmdlineDiffProvider.outputLine(line, normRegexp, diffs, firstText, secondText);
}
CmdlineDiffProvider.setTextOnLastDifference(diffs, firstText, secondText);
return diffs.toArray(new Difference[diffs.size()]);
}
示例13: prepareOverviewFilter
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
private synchronized void prepareOverviewFilter() {
if (overviewLabelFilters != null) {
return;
}
String filter = NbBundle.getMessage(JavadocSearchType.class, "FILTER_OverviewIndiceLabel"); // NOI18N
StringTokenizer tok = new StringTokenizer(filter, "\n"); // NOI18N
List<Pattern> ll = new LinkedList<Pattern>();
while (tok.hasMoreTokens()) {
try {
String expr = tok.nextToken();
Pattern re = Pattern.compile(expr);
ll.add(re);
} catch (PatternSyntaxException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
}
overviewLabelFilters = ll.toArray(new Pattern[ll.size()]);
}
示例14: getMatchingAttributes
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
private Attribute[] getMatchingAttributes(Attributes attributes, String regex) throws OperatorException {
Pattern pattern = null;
try {
pattern = Pattern.compile(regex);
} catch (PatternSyntaxException e) {
throw new UserError(this, 206, regex, e.getMessage());
}
List<Attribute> attributeList = new LinkedList<>();
Iterator<Attribute> iterator = attributes.allAttributes();
while (iterator.hasNext()) {
Attribute attribute = iterator.next();
if (pattern.matcher(attribute.getName()).matches()) {
attributeList.add(attribute);
}
}
// building array of attributes for faster access.
Attribute[] attributesArray = new Attribute[attributeList.size()];
attributesArray = attributeList.toArray(attributesArray);
return attributesArray;
}
示例15: RegexpPropertyMatcher
import java.util.regex.PatternSyntaxException; //导入依赖的package包/类
public RegexpPropertyMatcher(String name, String value, int flags) {
if (name == null) {
throw new IllegalArgumentException("Property name must not be null!");
}
if (value == null) {
throw new IllegalArgumentException("Property value pattern must not be null!");
}
this.name = name;
try {
valuePattern = Pattern.compile(value, flags);
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Bad pattern: " + value);
}
}