return new StrRegEx(argument.substring(1, argument.length() - 1));
/** * Constructs a new <tt>StrRegEx</tt> processor, which ensures that the input data matches the given regular * expression. * * @param regex * the regular expression to match * @throws NullPointerException * if regex is null * @throws IllegalArgumentException * if regex is empty * @throws PatternSyntaxException * if regex is not a valid regular expression */ public StrRegEx(final String regex) { super(); checkPreconditions(regex); this.regexPattern = Pattern.compile(regex); this.regex = regex; }
/** * {@inheritDoc} * * @throws SuperCsvCellProcessorException * if value is null * @throws SuperCsvConstraintViolationException * if value doesn't match the regular expression */ public Object execute(final Object value, final CsvContext context) { validateInputNotNull(value, context); final boolean matches = regexPattern.matcher((String) value).matches(); if( !matches ) { final String msg = REGEX_MSGS.get(regex); if( msg == null ) { throw new SuperCsvConstraintViolationException(String.format( "'%s' does not match the regular expression '%s'", value, regex), context, this); } else { throw new SuperCsvConstraintViolationException( String.format("'%s' does not match the constraint '%s' defined by the regular expression '%s'", value, msg, regex), context, this); } } return next.execute(value, context); }
/** * Constructs a new <tt>StrRegEx</tt> processor, which ensures that the input data matches the given regular * expression, then calls the next processor in the chain. * * @param regex * the regular expression to match * @param next * the next processor in the chain * @throws NullPointerException * if regex is null * @throws IllegalArgumentException * if regex is empty * @throws PatternSyntaxException * if regex is not a valid regular expression */ public StrRegEx(final String regex, final StringCellProcessor next) { super(next); checkPreconditions(regex); this.regexPattern = Pattern.compile(regex); this.regex = regex; }
final CellProcessor[] processors = new CellProcessor[] { new StrRegEx("\\w{3}"), // string value check new ParseDate("yyyy-MM-dd_HH:mm:ss", new DateToCalendar()) // date };
cellProcessor = new Equals(equals); } else if (StringUtils.isNotBlank(pattern)) { cellProcessor = new StrRegEx(pattern); } else if (strLen != null) { cellProcessor = new Strlen(strLen);
cellProcessor = new Equals(equals); } else if (StringUtils.isNotBlank(pattern)) { cellProcessor = new StrRegEx(pattern); } else if (strLen != null) { cellProcessor = new Strlen(strLen);
return new StrRegEx(argument.substring(1, argument.length() - 1));