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:com.dianping.lion.service.impl.PrivilegeServiceImpl.java
@Override public Resource getResourceMatchUrl(String url) { Resource matchedResource = cacheClient.get(ServiceConstants.CACHE_PRIV_URL_PREFIX + url); if (matchedResource == null) { List<Resource> allResources = getAllResource(); for (Resource resource : allResources) { String resourceUrl = resource.getUrl(); if (StringUtils.isNotBlank(resourceUrl)) { try { Pattern pattern = Pattern.compile("^" + resourceUrl + "$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(url); if (matcher.find()) { matchedResource = resource; break; }/*from w ww.j a va 2 s.com*/ } catch (PatternSyntaxException e) { logger.error("ResourceUrl[" + resourceUrl + "] is an invalid url pattern.", e); } } } if (matchedResource == null) { matchedResource = NullResource.INSTANCE; } cacheClient.set(ServiceConstants.CACHE_PRIV_URL_PREFIX + url, matchedResource); } return !NullResource.INSTANCE.equals(matchedResource) ? matchedResource : null; }
From source file:com.clustercontrol.monitor.run.factory.RunMonitorStringValueType.java
/** * ????/*w w w .j av a2 s .com*/ * <p> * ??????????? * ??????????????????? * * @see com.clustercontrol.monitor.run.ejb.entity.MonitorStringValueInfoBean#getOrder_no() * @see com.clustercontrol.monitor.run.bean.MonitorStringValueInfo */ @Override public int getCheckResult(boolean ret) { // -1 = ?-2 = ????? int result = -2; // ?? if (!ret) { result = -1; return result; } // ??? Pattern pattern = null; Matcher matcher = null; int orderNo = 0; // ?? for (MonitorJudgementInfo info : m_judgementInfoList.values()) { ++orderNo; if (m_log.isDebugEnabled()) { m_log.debug("getCheckResult() value = " + m_value + ", monitorId = " + info.getMonitorId() + ", orderNo = " + orderNo + ", pattern = " + info.getPattern()); } // ????? if (info != null && info.getValidFlg()) { try { String patternText = info.getPattern(); // ????? if (info.getCaseSensitivityFlg()) { pattern = Pattern.compile(patternText, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); } // ??? else { pattern = Pattern.compile(patternText, Pattern.DOTALL); } if (m_value == null) { m_log.debug("getCheckResult(): monitorId=" + info.getMonitorId() + ", facilityId=" + m_facilityId + ", value=null"); result = -1; return result; } matcher = pattern.matcher(m_value); // ???? if (matcher.matches()) { result = orderNo; m_log.debug("getCheckResult() true : description=" + info.getDescription() + ", value=" + m_value); m_log.debug("getCheckResult() true : message=" + info.getMessage()); break; } } catch (PatternSyntaxException e) { m_log.info("getCheckResult(): PatternSyntax is not valid." + " description=" + info.getDescription() + ", patternSyntax=" + info.getPattern() + ", value=" + m_value + " : " + e.getClass().getSimpleName() + ", " + e.getMessage()); result = -1; } catch (Exception e) { m_log.warn("getCheckResult(): PatternSyntax is not valid." + " description=" + info.getDescription() + ", patternSyntax=" + info.getPattern() + ", value=" + m_value + " : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); result = -1; } } } return result; }
From source file:com.puppycrawl.tools.checkstyle.checks.regexp.DetectorOptions.java
/** * The pattern to use when matching./* www. j a v a2s . c o m*/ * @return the pattern to use when matching. */ public Pattern getPattern() { if (pattern != null) { return pattern; } int options = compileFlags; if (ignoreCase) { options |= Pattern.CASE_INSENSITIVE; } pattern = Pattern.compile(format, options); return pattern; }
From source file:net.solarnetwork.web.support.UrlPathThemeResolver.java
public void setThemePathVariable(String themePathVariable) { this.themePathVariable = themePathVariable; urlPattern = Pattern.compile("\\b" + themePathVariable + "=(\\w+)", Pattern.CASE_INSENSITIVE); }
From source file:edu.jhuapl.dorset.agents.StockAgent.java
@Override public AgentResponse process(AgentRequest request) { logger.debug("Handling the request: " + request.getText()); // remove trigger word "stocks" String regex = "\\bstocks\\b"; Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); String requestCompanyName = pat.matcher(request.getText()).replaceAll("").trim(); CompanyInfo stockCompanyInfo = findStockSymbol(requestCompanyName); if (stockCompanyInfo == null) { return new AgentResponse(new ResponseStatus(ResponseStatus.Code.AGENT_DID_NOT_KNOW_ANSWER, "I am sorry, I don't understand which company you are asking about.")); }// w w w .j av a 2s .co m String keywordCompanyName = stockCompanyInfo.getName(); String keywordCompanySymbol = stockCompanyInfo.getSymbol(); String json = null; json = requestData(keywordCompanySymbol); if (json == null) { // replace ".." with "." to maintain proper grammar when the // keyword contains an abbreviation return new AgentResponse(new ResponseStatus(ResponseStatus.Code.AGENT_DID_NOT_KNOW_ANSWER, ("I am sorry, I can't find the proper stock data for the company " + keywordCompanyName + ".") .replace("..", "."))); } //See examples of the Json data returned by the API in src/test/resources/stockAgent JsonObject returnObj = processData(json, keywordCompanyName); // replace ".." with "." to maintain proper grammar when the // keyword contains an abbreviation if (returnObj != null) { return new AgentResponse( Response.Type.JSON, ("Here is the longitudinal stock market data from the last " + DAYS_IN_A_MONTH + " days for " + keywordCompanyName + ".").replace("..", "."), returnObj.toString()); } return new AgentResponse(ResponseStatus.Code.AGENT_DID_NOT_KNOW_ANSWER); }
From source file:de.uniwue.info6.misc.StringTools.java
/** * * * @param queryText/*from w w w . ja va 2 s . c o m*/ * @param tables * @param user * @return */ public static String addUserPrefix(String queryText, List<String> tables, User user) { LinkedList<Integer> substrings = new LinkedList<Integer>(); int start = 0, end = queryText.length(); for (String tab : tables) { // q&d fix Matcher matcher = Pattern.compile(tab.trim(), Pattern.CASE_INSENSITIVE).matcher(queryText); while (matcher.find()) { start = matcher.start(0); end = matcher.end(0); // String group = matcher.group(); boolean leftCharacterValid = StringTools.trailingCharacter(queryText, start, true); boolean rightCharacterValid = StringTools.trailingCharacter(queryText, end, false); if (leftCharacterValid && rightCharacterValid) { substrings.add(start); } } } Collections.sort(substrings); for (int i = substrings.size() - 1; i >= 0; i--) { Integer sub = substrings.get(i); queryText = queryText.substring(0, sub) + user.getId() + "_" + queryText.substring(sub, queryText.length()); } return queryText; }
From source file:com.norconex.collector.core.filter.impl.RegexMetadataFilter.java
public final void setRegex(String regex) { this.regex = regex; if (regex != null) { int flags = Pattern.DOTALL; if (!caseSensitive) { flags = flags | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE; }/*from w w w. jav a 2s . c o m*/ this.pattern = Pattern.compile(regex, flags); } else { this.pattern = Pattern.compile(".*"); } }
From source file:com.guang.eunormia.group.ZookeeperConfigManager.java
public static HAConfig parseConfig(String configString) { HAConfig config = new HAConfig(); // timeout/*from w ww . j a va 2 s. c om*/ Pattern p_timeout = Pattern.compile("timeout=([\\s\\S]+?);"); Matcher m_timeout = p_timeout.matcher(configString); if (m_timeout.find()) { String s_timeout = m_timeout.group(1); logger.info("timeout=" + s_timeout); try { config.timeout = Integer.parseInt(s_timeout.trim()); } catch (Exception ex) { logger.error("timeout?:", ex); } } // pool_size Pattern p_pool_size = Pattern.compile("pool_size=([\\s\\S]+?);"); Matcher m_pool_size = p_pool_size.matcher(configString); if (m_pool_size.find()) { String s_pool_size = m_pool_size.group(1); logger.info("pool_size=" + s_pool_size); try { config.pool_size = Integer.parseInt(s_pool_size.trim()); } catch (Exception ex) { logger.error("pool_size?:", ex); } } // password Pattern p_password = Pattern.compile("password=([\\s\\S]+?);"); Matcher m_password = p_password.matcher(configString); if (m_password.find()) { String s_password = m_password.group(1); logger.info("password=" + s_password); try { config.password = s_password.trim(); } catch (Exception ex) { logger.error("password?:", ex); } } // servers Pattern p = Pattern.compile("servers=([\\s\\S]+?);", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(configString); if (m.find()) { String s_servers = m.group(1); logger.info("servers=" + s_servers); String[] array = s_servers.trim().split(","); List<ServerProperties> servers = new ArrayList<ServerProperties>(); for (String s : array) { ServerProperties sp = new ServerProperties(); sp.server = new ServerInfo(); String[] ss = s.split(":"); if (ss.length >= 2) { sp.server.addr = ss[0]; sp.server.port = Integer.parseInt(ss[1]); sp.pool_size = config.pool_size; sp.timeout = config.timeout; sp.password = config.password; if (ss.length == 3) { sp.readWeight = Integer.parseInt(ss[2].toLowerCase().replace("r", "").trim()); } } else { logger.error("?:" + s); } servers.add(sp); } config.groups = servers; } else { logger.error("servers???:" + configString); } // fail over Pattern p_failover = Pattern.compile("failover=([\\s\\S]+?);", Pattern.CASE_INSENSITIVE); Matcher m_failover = p_failover.matcher(configString); if (m_failover.find()) { try { String s_failover = m.group(1); config.failover = Boolean.parseBoolean(s_failover.trim()); } catch (Throwable t) { logger.error("failover?", t); } } return config; }
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.SqlHelper.java
/** * orderby ??/*from w w w. j av a 2 s . co m*/ * * @param sql sql * @return order by sql */ public static String removeOrders(String sql) { Preconditions.checkNotNull(sql); Pattern p = Pattern.compile(ORDER_BY_REGEX, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(sql); StringBuffer sb = new StringBuffer(sql.length()); while (m.find()) { m.appendReplacement(sb, ""); } m.appendTail(sb); return sb.toString(); }
From source file:com.predic8.membrane.core.rules.ServiceProxyKey.java
public void setHost(String host) { this.host = host.trim(); this.isHostWildCard = "*".equals(this.host); if (!isHostWildCard) { String pattern = createHostPattern(this.host); log.debug("Created host pattern match: " + pattern); this.hostPattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); } else {/* w w w. j a v a2s . c o m*/ this.hostPattern = null; } }