/** * Returns a multi-line string containing the description of the syntax * error and its index, the erroneous regular-expression pattern, and a * visual indication of the error index within the pattern. * * @return The full detail message */ @Override /*@Pure*/ public String getMessage() { return pse.getMessage(); }
public RegexpMatcher(String term, boolean caseInsensitive) { super(caseInsensitive); Pattern regexp; try { regexp = Pattern.compile(term, caseInsensitive ? Pattern.CASE_INSENSITIVE : 0 ); } catch ( PatternSyntaxException e) { regexp = null; LOGGER.log(Level.WARNING, "RegexpMatcher: {0}", e.getMessage() ); } this.termRegexp = regexp; }
/** * Checks if the include regular expression is valid. */ public FormValidation doCheckIncludeRegex( @QueryParameter String value ) throws IOException, ServletException, InterruptedException { String v = Util.fixEmpty(value); if (v != null) { try { Pattern.compile(v); } catch (PatternSyntaxException pse) { return FormValidation.error(pse.getMessage()); } } return FormValidation.ok(); } }
/** * Create RegularExpressionValueMatcher with specified pattern. If pattern * is not null, it must be a valid regular expression that defines a * constant expected pattern that every actual value must match (in this * case the expected value passed to equal method will be ignored). If * pattern is null, the pattern the actual value must match with be * specified dynamically from the expected string passed to this matcher in * the equals method. * * @param pattern * if non null, regular expression pattern which all actual * values this matcher is applied to must match. If null, this * matcher will apply pattern specified dynamically via the * expected parameter to the equal method. * @throws IllegalArgumentException * if pattern is non-null and not a valid regular expression. */ public RegularExpressionValueMatcher(String pattern) throws IllegalArgumentException { try { expectedPattern = pattern == null ? null : Pattern.compile(pattern); } catch (PatternSyntaxException e) { throw new IllegalArgumentException("Constant expected pattern invalid: " + e.getMessage(), e); } }
public void init() { List<String> excludePatterns = Arrays.asList(MetastoreConf .getTrimmedStringsVar(conf, MetastoreConf.ConfVars.EVENT_NOTIFICATION_PARAMETERS_EXCLUDE_PATTERNS)); try { paramsFilter = MetaStoreUtils.compilePatternsToPredicates(excludePatterns); } catch (PatternSyntaxException e) { LOG.error("Regex pattern compilation failed. Verify that " + "metastore.notification.parameters.exclude.patterns has valid patterns."); throw new IllegalStateException("Regex pattern compilation failed. " + e.getMessage()); } }
public static BooleanValue regex( TextValue lhs, TextValue rhs ) { String regexString = rhs.stringValue(); try { boolean matches = Pattern.compile( regexString ).matcher( lhs.stringValue() ).matches(); return matches ? TRUE : FALSE; } catch ( PatternSyntaxException e ) { throw new InvalidSemanticsException( "Invalid Regex: " + e.getMessage() ); } }
private RegexTesterResponse doTestRegex(String example, String regex) { final Pattern pattern; try { pattern = Pattern.compile(regex, Pattern.DOTALL); } catch (PatternSyntaxException e) { throw new BadRequestException("Invalid regular expression: " + e.getMessage(), e); } final Matcher matcher = pattern.matcher(example); boolean matched = matcher.find(); // Get the first matched group. final RegexTesterResponse.Match match; if (matched && matcher.groupCount() > 0) { match = RegexTesterResponse.Match.create(matcher.group(1), matcher.start(1), matcher.end(1)); } else { match = null; } return RegexTesterResponse.create(matched, match, regex, example); } }
/** * Returns null if the argument is a syntactically valid regular * expression with at least the given number of groups. Otherwise returns * a string describing why the argument is not a regex. * @param s string to check for being a regular expression * @param groups number of groups expected * @return null, or a string describing why the argument is not a regex. */ @SuppressWarnings({"regex", "not.sef"}) // RegexUtil; /*@SideEffectFree*/ public static /*@Nullable*/ String regexError(String s, int groups) { try { Pattern p = Pattern.compile(s); int actualGroups = getGroupCount(p); if (actualGroups < groups) { return regexErrorMessage(s, groups, actualGroups); } } catch (PatternSyntaxException e) { return e.getMessage(); } return null; }
public static int isRegex(Configuration config, Field field, ValidationOutput problems) { String value = config.getString(field); int errors = 0; if (value != null) { try { Pattern.compile(value, Pattern.CASE_INSENSITIVE); } catch (PatternSyntaxException e) { problems.accept(field, value, "A valid regular expressions is expected, but " + e.getMessage()); ++errors; } } return errors; }
MOCK_SERVER_LOGGER.trace("Error while matching regex [" + matcher + "] for string [" + matched + "] " + pse.getMessage()); MOCK_SERVER_LOGGER.trace("Error while matching regex [" + matched + "] for string [" + matcher + "] " + pse.getMessage()); MOCK_SERVER_LOGGER.trace("Error while matching regex [" + matcher.toLowerCase() + "] for string [" + matched.toLowerCase() + "] " + pse.getMessage()); MOCK_SERVER_LOGGER.trace("Error while matching regex [" + matched.toLowerCase() + "] for string [" + matcher.toLowerCase() + "] " + pse.getMessage());
private Pattern determineClassNamePattern(Expression expr) { if (!(expr instanceof ConstantExpression)) { return null; } final ConstantExpression constExpr = (ConstantExpression) expr; final String text = constExpr.getText(); if (constExpr.getValue() == null || text.equals("")) { return null; } try { final Pattern pattern = Pattern.compile(text); return pattern; } catch (PatternSyntaxException e) { addError("Invalid class name pattern: " + e.getMessage(), expr); return null; } }
@Override public boolean equal(T actual, T expected) { String actualString = actual.toString(); String expectedString = expected.toString(); try { Pattern pattern = isStaticPattern() ? expectedPattern : Pattern .compile(expectedString); if (!pattern.matcher(actualString).matches()) { throw new ValueMatcherException(getPatternType() + " expected pattern did not match value", pattern.toString(), actualString); } } catch (PatternSyntaxException e) { throw new ValueMatcherException(getPatternType() + " expected pattern invalid: " + e.getMessage(), e, expectedString, actualString); } return true; }
return null; }catch(PatternSyntaxException e){ ret = new StringBuffer(e.getMessage());
return null; }catch(PatternSyntaxException e){ ret = new StringBuffer(e.getMessage());
public String render(String text) { if (StringUtils.isBlank(text)) { return ""; } if (regex.isEmpty() || link.isEmpty()) { Comment comment = new Comment(); comment.escapeAndAdd(text); return comment.render(); } try { Matcher matcher = Pattern.compile(regex).matcher(text); int start = 0; Comment comment = new Comment(); while (hasMatch(matcher)) { comment.escapeAndAdd(text.substring(start, matcher.start())); comment.add(dynamicLink(matcher)); start = matcher.end(); } comment.escapeAndAdd(text.substring(start)); return comment.render(); } catch (PatternSyntaxException e) { LOGGER.warn("Illegal regular expression: {} - {}", regex, e.getMessage()); } return text; }
public static int isListOfRegex(Configuration config, Field field, ValidationOutput problems) { String value = config.getString(field); int errors = 0; if (value != null) { try { Strings.setOfRegex(value, Pattern.CASE_INSENSITIVE); } catch (PatternSyntaxException e) { problems.accept(field, value, "A comma-separated list of valid regular expressions is expected, but " + e.getMessage()); ++errors; } } return errors; }
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (SplitFieldToRowsMeta) smi; data = (SplitFieldToRowsData) sdi; if ( super.init( smi, sdi ) ) { data.rownr = 1L; try { String delimiter = Const.nullToEmpty( meta.getDelimiter() ); if ( meta.isDelimiterRegex() ) { data.delimiterPattern = Pattern.compile( environmentSubstitute( delimiter ) ); } else { data.delimiterPattern = Pattern.compile( Pattern.quote( environmentSubstitute( delimiter ) ) ); } } catch ( PatternSyntaxException pse ) { log.logError( pse.getMessage() ); throw pse; } return true; } return false; } }
@Override public Description matchMethodInvocation( MethodInvocationTree methodInvocationTree, VisitorState state) { if (!BAD_REGEX_USAGE.matches(methodInvocationTree, state)) { return Description.NO_MATCH; } // TODO: Suggest fixes for more situations. Description.Builder descriptionBuilder = buildDescription(methodInvocationTree); ExpressionTree arg = methodInvocationTree.getArguments().get(0); String value = (String) ((JCExpression) arg).type.constValue(); String reasonInvalid = ""; if (".".equals(value)) { descriptionBuilder.addFix(SuggestedFix.replace(arg, "\"\\\\.\"")); reasonInvalid = "\".\" is a valid but useless regex"; } else { try { Pattern.compile(value); } catch (PatternSyntaxException e) { reasonInvalid = e.getMessage(); } } descriptionBuilder.setMessage(MESSAGE_BASE + reasonInvalid); return descriptionBuilder.build(); } }
/** Initialize the ModelBuilder, validating all arguments and preparing the * training frame. This call is expected to be overridden in the subclasses * and each subclass will start with "super.init();". This call is made * by the front-end whenever the GUI is clicked, and needs to be fast; * heavy-weight prep needs to wait for the trainModel() call. * * Validate the regex. */ @Override public void init(boolean expensive) { super.init(expensive); if( _parms._regex == null ) { error("_regex", "regex is missing"); } else { try { _pattern = Pattern.compile(_parms._regex); } catch( PatternSyntaxException pse ) { error("regex", pse.getMessage()); } } if( _parms._train == null ) return; Vec[] vecs = _parms.train().vecs(); if( vecs.length != 1 ) error("_train","Frame must contain exactly 1 Vec (of raw text)"); if( !(vecs[0] instanceof ByteVec) ) error("_train","Frame must contain exactly 1 Vec (of raw text)"); }
} catch (PatternSyntaxException e) { throw new SemanticException(ErrorMsg.INVALID_COLUMN.getMsg(sel, e .getMessage()));