List of usage examples for java.util.regex Pattern CASE_INSENSITIVE
int CASE_INSENSITIVE
To view the source code for java.util.regex Pattern CASE_INSENSITIVE.
Click Source Link
From source file:gov.nih.nci.cabig.caaers.utils.ranking.Ranker.java
public Ranker(String searchStr) { this.searchStr = searchStr; patternLength = searchStr.length();//from www . j a va 2 s. c o m escapedSearchStr = searchStr; //11 characters with special meanings: the opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar // or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ). // These special characters are often called "metacharacters". char[] metachars = new char[] { '\\', '(', ')', '[', ']', '^', '$', '.', '?', '+', '*', '|' }; if (StringUtils.containsAny(searchStr, metachars)) { String[] metaStr = { "\\", "(", ")", "[", "]", "^", "$", ".", "?", "+", "*", "|" }; String[] metaEscapedStr = { "\\\\", "\\(", "\\)", "\\[", "\\]", "\\^", "\\$", "\\.", "\\?", "\\+", "\\*", "\\|" }; escapedSearchStr = StringUtils.replaceEach(searchStr, metaStr, metaEscapedStr); } p = Pattern.compile(escapedSearchStr, Pattern.CASE_INSENSITIVE); }
From source file:org.energyos.espi.datacustodian.web.filter.CORSFilter.java
@SuppressWarnings("unchecked") // TODO: fix the class problem public void init(FilterConfig cfg) throws ServletException { // Process origin parameters String regex = cfg.getInitParameter("allow.origin.regex"); if (regex != null) { allowOriginRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); } else {// w ww . j av a 2 s. c o m allowOrigin = cfg.getInitParameter("allow.origin"); if (allowOrigin != null) { optionsHeaders.put("Access-Control-Allow-Origin", allowOrigin); } } // Process optional header parameters for (Enumeration<String> i = cfg.getInitParameterNames(); i.hasMoreElements();) { String name = i.nextElement(); if (name.startsWith("header:")) { optionsHeaders.put(name.substring(7), cfg.getInitParameter(name)); } } // Process Credential support parameter allowCredentials = cfg.getInitParameter("allow.credentials"); // Process Expose header parameter exposeHeaders = cfg.getInitParameter("expose.headers"); // Initialize default header values optionsHeaders.put("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type"); optionsHeaders.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); optionsHeaders.put("Access-Control-Max-Age", "1800"); }
From source file:com.yahoo.flowetl.core.util.RegexUtil.java
/** * Gets the pattern for the given string by providing the rules to do * extraction.//from w w w . j a v a2 s . c o m * * This is similar to how php does regex to match you provide in the format * /REGEX/options where options currently are "i" for case insensitive and * "u" for unicode and "m" for multiline and "s" for dotall and the value * inside the // is the regex to use * * @param str * the string to parsed the pattern out of * * @param cache * whether to cache the compiled pattern * * @return the pattern * * @throws PatternSyntaxException * * the pattern syntax exception if it has wrong syntax */ public static Pattern getPattern(String str, boolean cache) throws PatternSyntaxException { if (str == null) { return null; } // see if we made it before... Pattern p = compiledPats.get(str); if (p != null) { return p; } Matcher mat = patExtractor.matcher(str); if (mat.matches() == false) { throw new PatternSyntaxException("Invalid syntax provided", str, -1); } String regex = mat.group(1); String opts = mat.group(2); int optsVal = 0; if (StringUtils.contains(opts, "i")) { optsVal |= Pattern.CASE_INSENSITIVE; } if (StringUtils.contains(opts, "u")) { optsVal |= Pattern.UNICODE_CASE; } if (StringUtils.contains(opts, "m")) { optsVal |= Pattern.MULTILINE; } if (StringUtils.contains(opts, "s")) { optsVal |= Pattern.DOTALL; } // compile and store it p = Pattern.compile(regex, optsVal); if (cache) { compiledPats.put(str, p); } return p; }
From source file:com.evolveum.midpoint.prism.match.StringIgnoreCaseMatchingRule.java
@Override public boolean matchRegex(String a, String regex) { if (a == null) { return false; }/* w w w . j a v a 2 s. co m*/ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(a); return matcher.matches(); }
From source file:com.aurel.track.fieldType.runtime.matchers.run.StringMatcherRT.java
private void setPattern(String searchText) throws PatternSyntaxException { pattern = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); }
From source file:de.rnd7.libtvdb.util.EpisodeUtil.java
private static List<EpisodeInfo> parseNameInternal(final String name) throws IOException { final String filtered = filter(name.toLowerCase()); final List<EpisodeInfo> result = new ArrayList<EpisodeInfo>(); for (final Pattern pattern : PATTERN) { final Matcher matcher = pattern.matcher(filtered); boolean match = false; while (matcher.find()) { match = true;// www. j a v a 2 s .c om if (matcher.groupCount() == 3) { final int season = Integer.parseInt(matcher.group(1)); final int episodeA = Integer.parseInt(matcher.group(2)); final int episodeB = Integer.parseInt(matcher.group(3)); result.add(new EpisodeInfo(season, episodeA)); result.add(new EpisodeInfo(season, episodeB)); } else { final int season = Integer.parseInt(matcher.group(1)); final int episode = Integer.parseInt(matcher.group(2)); result.add(new EpisodeInfo(season, episode)); } } if (match) { break; } } if (result.isEmpty()) { // Fallback for single season series: final Pattern pattern = Pattern.compile(".*(\\d\\d).*", Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(filtered); if (matcher.matches()) { final int season = 1; final int episode = Integer.parseInt(matcher.group(1)); result.add(new EpisodeInfo(season, episode)); } } return result; }
From source file:io.github.chrisbotcom.reminder.CommandParser.java
public CommandParser(Reminder plugin) { this.plugin = plugin; // Compile regex pattern String commands = "add|list|delete|del|update|up|reload|stop|resume|start|time|setdefault|setdefaults|set|upgrade"; String tags = "tag|delay|rate|echo"; String cmd = String.format("(?<cmd>^%s)", commands); String id = "(?:\\s+)(?<id>\\d+)"; String tag = String.format("(?:\\s+)(?<tag>%s)(?:\\s+)(?<value>\\w+)", tags); String date = "(?:\\s+)(?<date>\\d{1,4}-\\d{1,2}-\\d{1,2})"; String time = "(?:\\s+)(?<time>\\d{1,2}:\\d{2})"; String offset = "(?:\\s+)(?<offset>\\+\\d+)"; String msg = "(?:\\s+)(?:[\\\"\\'])(?<msg>.*?)(?:[\\\"\\'])"; String player = "(?:\\s+)(?<player>\\w+|\\*)"; pattern = Pattern.compile(/*w w w . j av a 2s.c om*/ String.format("%s|%s|%s|%s|%s|%s|%s|%s", cmd, tag, date, time, offset, id, msg, player), Pattern.CASE_INSENSITIVE | Pattern.DOTALL); }
From source file:biz.letsweb.lukasfloorspring.interceptors.MobileInterceptor.java
public void init() { agentPatterns = new ArrayList<>(); // Pre-compile the user-agent patterns as specified in mvc.xml for (final String ua : mobileAgents) { try {/*from w w w.j a va 2 s. c om*/ agentPatterns.add(Pattern.compile(ua, Pattern.CASE_INSENSITIVE)); } catch (PatternSyntaxException e) { // Ignore the pattern, if it failed to compile // for whatever reason. } } }
From source file:at.molindo.notify.channel.mail.PatternMailClient.java
public void setClientPatterns(final List<String> smartClientPatterns) { _clientPatterns = new Pattern[smartClientPatterns.size()]; for (int i = 0; i < _clientPatterns.length; i++) { _clientPatterns[i] = Pattern.compile(smartClientPatterns.get(i), Pattern.CASE_INSENSITIVE); }/* w w w. j ava2 s .c o m*/ }
From source file:eagle.service.security.hdfs.resolver.HDFSCommandResolver.java
public List<String> resolve(GenericAttributeResolveRequest request) throws AttributeResolveException { String query = request.getQuery().trim(); List<String> res = new ArrayList<>(); for (String cmd : commands) { Pattern pattern = Pattern.compile("^" + query, Pattern.CASE_INSENSITIVE); if (pattern.matcher(cmd).find()) { res.add(cmd);// ww w. j a v a2s . c o m } } if (res.size() == 0) { return commands; } return res; }