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:net.longfalcon.newsj.Blacklist.java
public boolean isBlackListed(Article article, Group group) { boolean isBlackListed = false; String[] fields = new String[4]; fields[0] = ""; fields[Defaults.BLACKLIST_FIELD_SUBJECT] = article.getSubject(); fields[Defaults.BLACKLIST_FIELD_FROM] = article.getFrom(); fields[Defaults.BLACKLIST_FIELD_MESSAGEID] = article.getArticleId(); List<BinaryBlacklistEntry> blacklistEntries = getCachedBlacklist(); for (BinaryBlacklistEntry blacklistEntry : blacklistEntries) { Pattern groupPattern = Pattern.compile("^" + blacklistEntry.getGroupName() + "$", Pattern.CASE_INSENSITIVE); Matcher groupNameMatcher = groupPattern.matcher(group.getName()); if (groupNameMatcher.matches()) { Pattern blacklistPattern = Pattern.compile(blacklistEntry.getRegex(), Pattern.CASE_INSENSITIVE); String matcherText = fields[blacklistEntry.getMsgCol()]; Matcher blacklistMatcher = blacklistPattern.matcher(matcherText); if (blacklistEntry.getOpType() == 1) { // remove what matches if (blacklistMatcher.find()) { isBlackListed = true; }/* w w w . j a v a 2 s .c om*/ } else if (blacklistEntry.getOpType() == 2) { // remove all that doesnt match if (!blacklistMatcher.find()) { isBlackListed = true; } } } } return isBlackListed; }
From source file:edu.umn.se.trap.rule.grantrule.SponsoredNoInternetRule.java
/** * @param expense//www . j a v a 2 s . c o m * @throws TrapException */ private void checkSponsoredInternet(Expense expense) throws TrapException { /* * Check to make sure the expense is an other expense. */ if (expense.getType().equals(ExpenseType.OTHER)) { /* * Try to match "internet" or "wifi" in the justification field. */ Pattern alcoholPattern = Pattern.compile(internetRegex, Pattern.CASE_INSENSITIVE); Matcher alcoholMatcher = alcoholPattern.matcher(expense.getJustification()); // If internet is found, check the grants. if (alcoholMatcher.find()) { GrantSet grantSet = expense.getEligibleGrants(); if (grantSet == null) { throw new TrapException("Invalid TrapForm object: grantSet was null."); } Set<FormGrant> grants = grantSet.getGrants(); if (grants == null) { throw new TrapException("Invalid TrapForm object: grants was null."); } Iterator<FormGrant> grantIter = grants.iterator(); while (grantIter.hasNext()) { FormGrant grant = grantIter.next(); if (StringUtils.equalsIgnoreCase(grant.getAccountType(), "Sponsored")) { // Remove the grant if it is a sponsored grant trying to // cover internet. grantSet.removeGrant(grant.getAccountName()); } } } } }
From source file:jGPIO.DTO.java
/** * @param args/* www .ja v a 2s.c om*/ */ public DTO() { // determine the OS Version try { FileReader procVersion = new FileReader("/proc/version"); char[] buffer = new char[100]; procVersion.read(buffer); procVersion.close(); String fullVersion = new String(buffer); String re1 = "(Linux)"; // Word 1 String re2 = "( )"; // Any Single Character 1 String re3 = "(version)"; // Word 2 String re4 = "( )"; // Any Single Character 2 String re5 = "(\\d+)"; // Integer Number 1 String re6 = "(\\.)"; // Any Single Character 3 String re7 = "(\\d+)"; // Integer Number 2 String re8 = "(\\.)"; // Any Single Character 4 String re9 = "(\\d+)"; // Integer Number 3 Pattern p = Pattern.compile(re1 + re2 + re3 + re4 + re5 + re6 + re7 + re8 + re9, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(fullVersion); if (m.find()) { Integer linuxMajor = Integer.parseInt(m.group(5)); Integer linuxMinor = Integer.parseInt(m.group(7)); if (linuxMajor >= 3 && linuxMinor >= 8) { requireDTO = true; } } } catch (FileNotFoundException e) { System.out.println("Couldn't read the /proc/version. Please check for why it doesn't exist!\n"); System.exit(1); } catch (IOException e) { System.out.println("Couldn't read in from /proc/version. Please cat it to ensure it is valid\n"); } // no DTO generation required, so we'll exit and the customer can check // for requireDTO to be false if (!requireDTO) { System.out.println("No need for DTO"); return; } // load the file containing the GPIO Definitions from the property file try { definitionFile = System.getProperty("gpio_definition"); // No definition file, try an alternative name if (definitionFile == null) { System.getProperty("gpio_definitions"); } if (definitionFile == null) { // Still no definition file, try to autodetect it. definitionFile = autoDetectSystemFile(); } JSONParser parser = new JSONParser(); System.out.println("Using GPIO Definitions file: " + definitionFile); pinDefinitions = (JSONArray) parser.parse(new FileReader(definitionFile)); } catch (NullPointerException NPE) { System.out.println( "Could not read the property for gpio_definition, please set this since you are on Linux kernel 3.8 or above"); System.exit(-1); } catch (FileNotFoundException e) { System.out.println("Could not read the GPIO Definitions file"); e.printStackTrace(); System.exit(-1); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } catch (ParseException e) { e.printStackTrace(); System.exit(-1); } }
From source file:framework.retrieval.engine.common.RetrievalUtil.java
/** * HTML?/* w w w . j a va2 s . c om*/ * @param htmlContent * @param charsetName * @return */ public static String parseHTML(String htmlContent, String charsetName) { if (null == htmlContent || "".equals(htmlContent.trim())) { return htmlContent; } StringBuffer txt = new StringBuffer(); Pattern pattern = Pattern.compile("<[^<|^>]*>", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(htmlContent); while (matcher.find()) { String group = matcher.group(); if (group.matches("<[\\s]*>")) { matcher.appendReplacement(txt, group); } else { matcher.appendReplacement(txt, ""); } } matcher.appendTail(txt); String str = txt.toString(); return str; }
From source file:com.ning.maven.plugins.duplicatefinder.Exception.java
public void setResourcePatterns(String[] resourcePatterns) { this.matchingResources = new Pattern[resourcePatterns.length]; for (int i = 0; i < resourcePatterns.length; i++) { this.matchingResources[i] = Pattern.compile(resourcePatterns[i], Pattern.CASE_INSENSITIVE); }// www .j a va 2s.c o m }
From source file:com.seer.datacruncher.spring.MacrosValidateController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String varList = request.getParameter("varList"); String rule = request.getParameter("rule"); Long schemaId = Long.valueOf(request.getParameter("schemaId")); if (rule == null) { throw new IllegalArgumentException("MacrosValidateController: null parameter 'rule'"); }/*from w ww . j a va 2s .co m*/ String success = "true"; Map<String, String> resMap = new HashMap<String, String>(); if (rule.trim().isEmpty()) { success = "false"; resMap.put("errMsg", I18n.getMessage("error.macro.emptyRule")); } Pattern pattern = Pattern.compile(MacroRulesValidation.MACRO_SQL_VALIDATOR_PATTERN, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(rule); rule = matcher.replaceAll("true"); List<Map<String, String>> list = MacroRulesValidation.parseVars(varList); MacroRulesValidation.combineVariableLists(list, schemaId); JexlEngine jexl = JexlEngineFactory.getInstance(); try { Expression e = jexl.createExpression(rule); JexlContext context = new MapContext(); for (Map<String, String> m : list) { String anyStringDigit = "7"; context.set(m.get("uniqueName"), JEXLFieldFactory.getField(m.get("fieldType"), anyStringDigit).getValue()); } e.evaluate(context); } catch (Exception e1) { success = "false"; resMap.put("errMsg", e1.getMessage() + "\n" + getStackTrace(e1)); } resMap.put("success", success); response.getWriter().print(new JSONObject(resMap).toString()); return null; }
From source file:de.decoit.visa.net.IPAddress.java
/** * Construct a new object using the specified IP address and version. The * address will be checked to be valid for the provided version of the IP * protocol. Additionally it will be checked if the address is a link local * address.// ww w . ja va 2 s. c om * * @param pAddress String notation of the IP address, must be valid for the * provided IP version * @param pVersion Version of the Internet Protocol which will be used for * this address */ IPAddress(String pAddress, IPVersion pVersion) { String[] addressParts; Matcher addrMatcher; Matcher linkLocalMatcher; if (pVersion == IPVersion.V4) { // Check if the IP address is valid Pattern ip4pattern = Pattern.compile( "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", Pattern.CASE_INSENSITIVE); addrMatcher = ip4pattern.matcher(pAddress); Pattern linkLocalPattern = Pattern.compile( "^169\\.254\\.(?:25[0-4]|2[0-4][0-9]|1[0-9][0-9]?|[1-9])\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", Pattern.CASE_INSENSITIVE); linkLocalMatcher = linkLocalPattern.matcher(pAddress); } else if (pVersion == IPVersion.V6) { // Check if the IP address is valid Pattern ip6pattern = Pattern.compile( "^(((?=(?>.*?::)(?!.*::)))(::)?([0-9A-F]{1,4}::?){0,5}|([0-9A-F]{1,4}:){6})(\\2([0-9A-F]{1,4}(::?|$)){0,2}|((25[0-5]|(2[0-4]|1\\d|[1-9])?\\d)(\\.|$)){4}|[0-9A-F]{1,4}:[0-9A-F]{1,4})(?<![^:]:|\\.)\\z", Pattern.CASE_INSENSITIVE); addrMatcher = ip6pattern.matcher(pAddress); // Check if this address is a link-local address Pattern linkLocalPattern = Pattern.compile("^FE80(?::0000){3}(?::[0-9A-F]{4}){4}$", Pattern.CASE_INSENSITIVE); linkLocalMatcher = linkLocalPattern.matcher(pAddress); } else { throw new IllegalArgumentException("Invalid IP version provided"); } if (addrMatcher.matches()) { ipAddress = pAddress; ipVersion = pVersion; addressParts = pAddress.split(ipVersion.getNotationSplitRegex()); ipAddressGroups = new int[addressParts.length]; for (int i = 0; i < addressParts.length; i++) { ipAddressGroups[i] = Integer.parseInt(addressParts[i], ipVersion.getNotationRadix()); } // Check if this address is a link-local address isLinkLocal = linkLocalMatcher.matches(); } else { throw new IllegalArgumentException("Malformed IP or network address"); } }
From source file:net.java.sip.communicator.impl.gui.main.chat.replacers.KeywordReplacer.java
/** * Replace operation. Searches for the keyword in the provided piece of * content and replaces it with the piece of content surrounded by <b> * tags./*from w w w . j a va 2 s . c o m*/ * * @param target the destination to write the result to * @param piece the piece of content to process */ @Override public void replace(final StringBuilder target, final String piece) { if (this.keyword == null || this.keyword.isEmpty()) { target.append(StringEscapeUtils.escapeHtml4(piece)); return; } final Matcher m = Pattern .compile("(^|\\W)(" + Pattern.quote(keyword) + ")(\\W|$)", Pattern.CASE_INSENSITIVE).matcher(piece); int prevEnd = 0; while (m.find()) { target.append(StringEscapeUtils.escapeHtml4( piece.substring(prevEnd, m.start() + m.group(INDEX_OPTIONAL_PREFIX_GROUP).length()))); prevEnd = m.end() - m.group(INDEX_OPTIONAL_SUFFIX_GROUP).length(); final String keywordMatch = m.group(INDEX_KEYWORD_MATCH_GROUP).trim(); target.append("<b>"); target.append(StringEscapeUtils.escapeHtml4(keywordMatch)); target.append("</b>"); } target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd))); }
From source file:io.acme.solution.api.validation.UserProfileValidator.java
private void rejectIfNotUsername(final UserProfile profile, final Errors errors) { Pattern validUsernamePattern = Pattern.compile(USERNAME_PATTERN, Pattern.CASE_INSENSITIVE); if (!validUsernamePattern.matcher(profile.getUsername()).matches()) { errors.rejectValue(UserProfile.FIELD_USERNAME, MessageKeys.UserProfile.INVALID_USERNAME); }//from w ww. ja v a 2s . co m }
From source file:dinamica.util.matcher.RegexRequestMatcher.java
/** * As above, but allows setting of whether case-insensitive matching should be used. * * @param pattern the regular expression to compile into a pattern. * @param httpMethod the HTTP method to match. May be null to match all methods. * @param caseInsensitive if true, the pattern will be compiled with the * {@link Pattern#CASE_INSENSITIVE} flag set. */// w ww . ja va 2s . c om public RegexRequestMatcher(String pattern, String httpMethod, boolean caseInsensitive) { if (caseInsensitive) { this.pattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); } else { this.pattern = Pattern.compile(pattern); } this.httpMethod = StringUtils.hasText(httpMethod) ? HttpMethod.valueOf(httpMethod) : null; }