return RegExUtils.removeAll(text, regex);
@Test public void testRemoveAll_StringPattern() { assertNull(RegExUtils.removeAll(null, Pattern.compile(""))); assertEquals("any", RegExUtils.removeAll("any", (Pattern) null)); assertEquals("any", RegExUtils.removeAll("any", Pattern.compile(""))); assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".*"))); assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".+"))); assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".?"))); assertEquals("A\nB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("<.*>"))); assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("(?s)<.*>"))); assertEquals("ABC123", RegExUtils.removeAll("ABCabc123abc", Pattern.compile("[a-z]"))); assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("<.*>", Pattern.DOTALL))); assertEquals("AB", RegExUtils.removeAll("A<__>\\n<__>B", Pattern.compile("<.*>"))); assertEquals("", RegExUtils.removeAll("<A>x\\ny</A>", Pattern.compile("<A>.*</A>"))); assertEquals("", RegExUtils.removeAll("<A>\nxy\n</A>", Pattern.compile("<A>.*</A>", Pattern.DOTALL))); }
@Test public void testRemoveAll_StringString() { assertNull(RegExUtils.removeAll(null, "")); assertEquals("any", RegExUtils.removeAll("any", (String) null)); assertEquals("any", RegExUtils.removeAll("any", "")); assertEquals("", RegExUtils.removeAll("any", ".*")); assertEquals("", RegExUtils.removeAll("any", ".+")); assertEquals("", RegExUtils.removeAll("any", ".?")); assertEquals("A\nB", RegExUtils.removeAll("A<__>\n<__>B", "<.*>")); assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", "(?s)<.*>")); assertEquals("ABC123", RegExUtils.removeAll("ABCabc123abc", "[a-z]")); try { RegExUtils.removeAll("any", "{badRegexSyntax}"); fail("RegExUtils.removeAll expecting PatternSyntaxException"); } catch (final PatternSyntaxException ex) { // empty } }
@Override public Map<String, Object> getAttributes(final HttpServletRequest request) { return Collections.list(request .getHeaderNames()) .stream() .filter(t -> t.toUpperCase().startsWith(PREFIX)) .filter(t -> StringUtils.isNotBlank(request.getHeader(t))) .map(t -> RegExUtils.removeAll(t, PREFIX)) .collect(Collectors.toMap(Function.identity(), t -> CollectionUtils.wrap(request.getHeader(PREFIX + t).split("(?<!\\\\);")))); } }
return RegExUtils.removeAll(text, regex);
return RegExUtils.removeAll(text, regex);
return RegExUtils.removeAll(text, regex);
public String sanitizeQueryString(String query, HttpServletRequest req) { String qf = getSpaceFilteredQuery(req); String defaultQuery = "*"; String q = StringUtils.trimToEmpty(query); if (qf.isEmpty() || qf.length() > 1) { q = q.replaceAll("[\\*\\?]", "").trim(); q = RegExUtils.removeAll(q, "AND"); q = RegExUtils.removeAll(q, "OR"); q = RegExUtils.removeAll(q, "NOT"); q = q.trim(); defaultQuery = ""; } if (qf.isEmpty()) { return defaultQuery; } else if ("*".equals(qf)) { return q; } else { if (q.isEmpty()) { return qf; } else { return qf + " AND " + q; } } }
@Override public ZonedDateTime read(final Kryo kryo, final Input input, final Class<ZonedDateTime> type) { val time = kryo.readObject(input, Long.class); val zoneId = RegExUtils.removeAll(input.readString().trim(), "\\p{C}"); try { LOGGER.trace("Reading zoned date time instance with time [{}] and zone id [{}]", time, zoneId); val zone = ZoneId.of(zoneId); return DateTimeUtils.zonedDateTimeOf(time, zone); } catch (final Exception e) { LOGGER.warn("Unable to parse a zoned datetime instance with time [{}] and zone id [{}]: [{}]", time, zoneId, e.getMessage()); return DateTimeUtils.zonedDateTimeOf(time, ZoneId.systemDefault()); } } }