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:org.rotarysource.core.statements.StatmntPrepare.java
/** * Method to Statement registering in a EventProcessor engine * //from w ww . ja va 2 s.c om * @param EPServiceProvider * . Esper Event Processor engine where register the statement. */ @Override public void register(EPServiceProvider cepEngine) { log.info("Registering Statement: {}", eplStatement); if (statementObj != null) { log.debug("Statement registered yet. Destroying"); statementObj.destroy(); statementObj = null; } try { statementObj = cepEngine.getEPAdministrator().createEPL(eplStatement); } catch (EPStatementExistsException exception) { log.warn(exception.getMessage()); // EPL statement can be named using @Name() notation in EPL sentence. // Statement object hasnt any Name reference to recover the EPL so // Its necessary to parse the EPL to recover the EPL Name String eplName = null; String expression = ".*@Name\\('.*'\\).*"; //Make the comparison case-insensitive. Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(eplStatement); if (matcher.matches()) { eplName = eplStatement.split("@Name\\('")[1].split("'\\)")[0]; log.debug("Localized EPL Name in EPL Statement: " + eplName); } statementObj = cepEngine.getEPAdministrator().getStatement(eplName); log.warn("Recovered EplName={}", eplName); } catch (EPStatementSyntaxException exception) { log.error("Syntax error exception registering EPL; nested Message {}", exception.getMessage()); throw exception; } catch (EPStatementException exception) { log.error("Error registering EPL; nested Message {}", exception.getMessage()); throw exception; } log.info("Successfull registered Statement: {}", getEplName()); }
From source file:TelnetTest.java
public void testPs() throws IOException { int maxIter = 2; for (int i = 0; i < maxIter; i++) { os.write("ps\r\n".getBytes()); os.flush();//w w w . j a va 2s .co m String s = readUntil(is, prompt); s = s.substring(0, s.indexOf(prompt)); System.out.println(s); System.out.println("iteration " + (i + 1) + " of " + maxIter); Pattern p = Pattern.compile(".*ps.EXE\\[2000ee91\\]\\d\\d\\d\\d\r\n$", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); //Pattern.DOTALL => '.' includes end of line Matcher m = p.matcher(s); assertTrue(m.matches()); } }
From source file:com.osrdata.etltoolbox.fileloader.FileSpecification.java
/** * Constructs and initializes this object using source to target specifications contained in specification file. * @param spec file name of JSON formatted file that contains source to target specifications *//*w ww . j a v a 2s . c o m*/ public FileSpecification(Map<String, Object> spec, DataSource auditDs, DataSource targetDs, int batchThreshold, boolean replaceExisting, long trace) { String stringProperty = (String) spec.get("sourcePattern"); sourcePattern = Pattern.compile(stringProperty, Pattern.CASE_INSENSITIVE); if (spec.containsKey("parserLine")) { parserLine = (Integer) spec.get("parserLine"); } if (spec.containsKey("parserSeparator")) { stringProperty = (String) spec.get("parserSeparator"); parserSeparator = stringProperty.charAt(0); } if (spec.containsKey("parserQuotechar")) { stringProperty = (String) spec.get("parserQuotechar"); parserQuotechar = stringProperty.charAt(0); } if (spec.containsKey("parserEscape")) { stringProperty = (String) spec.get("parserEscape"); parserEscape = stringProperty.charAt(0); } dateGroup = (Integer) spec.get("dateGroup"); dateFormat = (String) spec.get("dateFormat"); typeGroup = (Integer) spec.get("typeGroup"); sourceId = (Integer) spec.get("sourceId"); targetTable = (String) spec.get("targetTable"); targetColumns = (List<String>) spec.get("targetColumns"); this.auditDs = auditDs; this.targetDs = targetDs; this.batchThreshold = batchThreshold; this.replaceExisting = replaceExisting; this.trace = trace; StringBuffer sb = new StringBuffer(); sb.append("insert into ").append(targetTable).append(" ("); boolean firstColumn = true; for (int i = 0; i < targetColumns.size(); i++) { // Columns defined as empty string indicate that they should be skipped if (!targetColumns.get(i).equals("")) { if (firstColumn) { sb.append(targetColumns.get(i)); firstColumn = false; } else { sb.append(", ").append(targetColumns.get(i)); } } } if (sourceId != null) { sb.append(", source_id, file_id, record_id)"); } else { sb.append(")"); } sb.append(" values ("); firstColumn = true; for (int i = 0; i < targetColumns.size(); i++) { // Columns defined as empty string indicate that they should be skipped if (!targetColumns.get(i).equals("")) { if (firstColumn) { sb.append("?"); firstColumn = false; } else { sb.append(", ?"); } numColumns++; } } // If source ID is not defined, then do not include source ID, file ID, and record ID fields. if (sourceId != null) { sb.append(", ?, ?, ?)"); numColumns += 3; } else { sb.append(")"); } targetSql = sb.toString(); }
From source file:org.webcat.notifications.googlevoice.GoogleVoice.java
/** * Logs in to the Google Voice service./*w w w . j ava2 s.co m*/ */ public void login() { HttpUriRequest request = buildRequest(CLIENT_LOGIN_URL, true, "accountType", "GOOGLE", "Email", username, "Passwd", password, "service", "grandcentral", "source", source); new AsyncURLConnection(request, new SimpleURLConnectionDelegate() { public void didFinishLoading() { if (statusCode() == HttpStatus.SC_OK) { Pattern pattern = Pattern.compile("^auth=(.*)$", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher matcher = pattern.matcher(responseString()); if (matcher.find()) { authToken = matcher.group(1); } if (authToken != null) { getRnrSeToken(); } else { delegate.loginFailed(GoogleVoice.this, new IOException("No authorization token received.")); } } else { delegate.loginFailed(GoogleVoice.this, new IOException("Google Voice login failed with status code " + statusCode())); } } public void didFailWithException(IOException e) { delegate.loginFailed(GoogleVoice.this, e); } }); }
From source file:com.bealearts.template.SimpleTemplate.java
/** * Parse the template/* w w w .java2 s.c om*/ */ private void parseTemplate(String content) { Pattern pattern = Pattern.compile( "<!--\\s*(BEGIN|END)\\s*:\\s*(\\w+)\\s*-->(.*?)(?=(?:<!--\\s*(?:BEGIN|END)\\s*:\\s*\\w+\\s*-->)|(?:\\s*$))", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher matcher = pattern.matcher(content); BlockContent currentBlock = null; String currentBlockPath = ""; while (matcher.find()) { if (matcher.group(1).equalsIgnoreCase("BEGIN")) { if (currentBlock == null) currentBlock = new BlockContent(); else currentBlock = (BlockContent) currentBlock.addContentItem(new BlockContent()); currentBlock.setName(matcher.group(2)); if (currentBlockPath.equals("")) currentBlockPath = currentBlock.getName(); else currentBlockPath += "." + currentBlock.getName(); this.blockMap.put(currentBlockPath, currentBlock); } else if (matcher.group(1).equalsIgnoreCase("END")) { currentBlock = currentBlock.getParent(); if (currentBlock != null) currentBlockPath = currentBlockPath.substring(0, currentBlockPath.lastIndexOf(".")); } if (currentBlock != null && matcher.group(3) != null && !matcher.group(3).equals("")) currentBlock.addContentItem(new TextContent(matcher.group(3))); } }
From source file:com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenTextCheck.java
/** * Set whether or not the match is case sensitive. * @param caseInsensitive true if the match is case insensitive. *///from w w w . j ava 2 s . c o m public void setIgnoreCase(boolean caseInsensitive) { if (caseInsensitive) { setCompileFlags(Pattern.CASE_INSENSITIVE); } }
From source file:com.norconex.collector.http.filter.impl.RegexHeaderFilter.java
public final void setRegex(String regex) { this.regex = regex; if (regex != null) { if (caseSensitive) { this.pattern = Pattern.compile(regex); } else {/* w w w. ja va2 s.com*/ this.pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); } } else { this.pattern = Pattern.compile(".*"); } }
From source file:gov.va.vinci.v3nlp.negex.GenNegEx.java
public String negCheck(String sentenceString, String phraseString, List<String> ruleStrings, boolean negatePossible) throws Exception { Sorter s = new Sorter(); String sToReturn = ""; String sScope = ""; List<String> sortedRules = new ArrayList<String>(); String filler = "_"; boolean negPoss = negatePossible; // Sort the rules by length in descending order. // Rules need to be sorted so the longest rule is always tried to match // first./* w ww .ja v a 2s . c o m*/ // Some of the rules overlap so without sorting first shorter rules (some of them POSSIBLE or PSEUDO) // would match before longer legitimate negation rules. // // There is efficiency issue here. It is better if rules are sorted by the // calling program once and used without sorting in GennegEx. sortedRules = s.sortRules(ruleStrings); // Process the sentence and tag each matched negation // rule with correct negation rule tag. // // At the same time check for the phrase that we want to decide // the negation status for and // tag the phrase with [PHRASE] ... [PHRASE] // In both the negation rules and in the phrase replace white space // with "filler" string. (This could cause problems if the sentences // we study has "filler" on their own.) // Sentence needs one character in the beginning and end to match. // We remove the extra characters after processing. String sentence = "." + sentenceString + "."; // Tag the phrases we want to detect for negation. // Should happen before rule detection. String phrase = phraseString; Pattern pph = null; try { pph = Pattern.compile(phrase.trim(), Pattern.CASE_INSENSITIVE); } catch (Exception e) { // IF There was an exception, escape the phrase for special regex characters. It is more // efficient to only escape if an error, as most phrases will work fine. logger.info("In Special processing... (" + phrase.trim() + ")"); pph = Pattern.compile(escapeRegexCharacters(phrase.trim()), Pattern.CASE_INSENSITIVE); } Matcher mph = pph.matcher(sentence); while (mph.find() == true) { sentence = mph.replaceAll(" [PHRASE]" + mph.group().trim().replaceAll(" ", filler) + "[PHRASE]"); } Iterator<String> iRule = sortedRules.iterator(); while (iRule.hasNext()) { String rule = iRule.next(); Pattern p = Pattern.compile("[\\t]+"); // Working. String[] ruleTokens = p.split(rule.trim()); // Add the regular expression characters to tokens and asemble the rule again. String[] ruleMembers = ruleTokens[0].trim().split(" "); String rule2 = ""; for (int i = 0; i <= ruleMembers.length - 1; i++) { if (!ruleMembers[i].equals("")) { if (ruleMembers.length == 1) { rule2 = ruleMembers[i]; } else { rule2 = rule2 + ruleMembers[i].trim() + "\\s+"; } } } // Remove the last s+ if (rule2.endsWith("\\s+")) { rule2 = rule2.substring(0, rule2.lastIndexOf("\\s+")); } rule2 = "(?m)(?i)[[\\p{Punct}&&[^\\]\\[]]|\\s+](" + rule2 + ")[[\\p{Punct}&&[^_]]|\\s+]"; Pattern p2 = Pattern.compile(ruleTokens[0].trim()); Matcher m = p2.matcher(sentence); while (m.find()) { String rpWith = ruleTokens[2].substring(2).trim(); sentence = m.replaceAll(" " + rpWith + m.group().trim().replaceAll(" ", filler) + rpWith + " "); } } // Exchange the [PHRASE] ... [PHRASE] tags for [NEGATED] ... [NEGATED] // based of PREN, POST rules and if flag is set to true // then based on PREP and POSP, as well. // Because PRENEGATION [PREN} is checked first it takes precedent over // POSTNEGATION [POST]. // Similarly POSTNEGATION [POST] takes precedent over POSSIBLE PRENEGATION [PREP] // and [PREP] takes precedent over POSSIBLE POSTNEGATION [POSP]. Pattern pSpace = Pattern.compile("[\\s+]"); String[] sentenceTokens = pSpace.split(sentence); StringBuilder sb = new StringBuilder(); // Check for [PREN] for (int i = 0; i < sentenceTokens.length; i++) { sb.append(" " + sentenceTokens[i].trim()); if (sentenceTokens[i].trim().startsWith("[PREN]") || sentenceTokens[i].trim().startsWith("[PRE_NEG]")) { for (int j = i + 1; j < sentenceTokens.length; j++) { if (sentenceTokens[j].trim().startsWith("[CONJ]") || sentenceTokens[j].trim().startsWith("[PSEU]") || sentenceTokens[j].trim().startsWith("[POST]") || sentenceTokens[j].trim().startsWith("[PREP]") || sentenceTokens[j].trim().startsWith("[POSP]")) { break; } if (sentenceTokens[j].trim().startsWith("[PHRASE]")) { sentenceTokens[j] = sentenceTokens[j].trim().replaceAll("\\[PHRASE\\]", "[NEGATED]"); } } } } sentence = sb.toString(); pSpace = Pattern.compile("[\\s+]"); sentenceTokens = pSpace.split(sentence); StringBuilder sb2 = new StringBuilder(); // Check for [POST] for (int i = sentenceTokens.length - 1; i > 0; i--) { sb2.insert(0, sentenceTokens[i] + " "); if (sentenceTokens[i].trim().startsWith("[POST]")) { for (int j = i - 1; j > 0; j--) { if (sentenceTokens[j].trim().startsWith("[CONJ]") || sentenceTokens[j].trim().startsWith("[PSEU]") || sentenceTokens[j].trim().startsWith("[PRE_NEG]") || sentenceTokens[j].trim().startsWith("[PREN]") || sentenceTokens[j].trim().startsWith("[PREP]") || sentenceTokens[j].trim().startsWith("[POSP]")) { break; } if (sentenceTokens[j].trim().startsWith("[PHRASE]")) { sentenceTokens[j] = sentenceTokens[j].trim().replaceAll("\\[PHRASE\\]", "[NEGATED]"); } } } } sentence = sb2.toString(); // If POSSIBLE negation is detected as negation. // negatePossible being set to "true" then check for [PREP] and [POSP]. if (negPoss == true) { pSpace = Pattern.compile("[\\s+]"); sentenceTokens = pSpace.split(sentence); StringBuilder sb3 = new StringBuilder(); // Check for [PREP] for (int i = 0; i < sentenceTokens.length; i++) { sb3.append(" " + sentenceTokens[i].trim()); if (sentenceTokens[i].trim().startsWith("[PREP]")) { for (int j = i + 1; j < sentenceTokens.length; j++) { if (sentenceTokens[j].trim().startsWith("[CONJ]") || sentenceTokens[j].trim().startsWith("[PSEU]") || sentenceTokens[j].trim().startsWith("[POST]") || sentenceTokens[j].trim().startsWith("[PRE_NEG]") || sentenceTokens[j].trim().startsWith("[PREN]") || sentenceTokens[j].trim().startsWith("[POSP]")) { break; } if (sentenceTokens[j].trim().startsWith("[PHRASE]")) { sentenceTokens[j] = sentenceTokens[j].trim().replaceAll("\\[PHRASE\\]", "[POSSIBLE]"); } } } } sentence = sb3.toString(); pSpace = Pattern.compile("[\\s+]"); sentenceTokens = pSpace.split(sentence); StringBuilder sb4 = new StringBuilder(); // Check for [POSP] for (int i = sentenceTokens.length - 1; i > 0; i--) { sb4.insert(0, sentenceTokens[i] + " "); if (sentenceTokens[i].trim().startsWith("[POSP]")) { for (int j = i - 1; j > 0; j--) { if (sentenceTokens[j].trim().startsWith("[CONJ]") || sentenceTokens[j].trim().startsWith("[PSEU]") || sentenceTokens[j].trim().startsWith("[PREN]") || sentenceTokens[j].trim().startsWith("[PRE_NEG]") || sentenceTokens[j].trim().startsWith("[PREP]") || sentenceTokens[j].trim().startsWith("[POST]")) { break; } if (sentenceTokens[j].trim().startsWith("[PHRASE]")) { sentenceTokens[j] = sentenceTokens[j].trim().replaceAll("\\[PHRASE\\]", "[POSSIBLE]"); } } } } sentence = sb4.toString(); } // Remove the filler character we used. sentence = sentence.replaceAll(filler, " "); // Remove the extra periods at the beginning // and end of the sentence. sentence = sentence.substring(0, sentence.trim().lastIndexOf('.')); sentence = sentence.replaceFirst(".", ""); // Get the scope of the negation for PREN and PREP if (sentence.contains("[PRE_NEG]") || sentence.contains("[PREN]") || sentence.contains("[PREP]")) { int startOffset = sentence.indexOf("[PREN]"); if (startOffset == -1) { startOffset = sentence.indexOf("[PRE_NEG]"); } if (startOffset == -1) { startOffset = sentence.indexOf("[PREP]"); } int endOffset = sentence.indexOf("[CONJ]"); if (endOffset == -1) { endOffset = sentence.indexOf("[PSEU]"); } if (endOffset == -1) { endOffset = sentence.indexOf("[POST]"); } if (endOffset == -1) { endOffset = sentence.indexOf("[POSP]"); } if (endOffset == -1 || endOffset < startOffset) { endOffset = sentence.length() - 1; } sScope = sentence.substring(startOffset, endOffset + 1); } // Get the scope of the negation for POST and POSP if (sentence.contains("[POST]") || sentence.contains("[POSP]")) { int endOffset = sentence.lastIndexOf("[POST]"); if (endOffset == -1) { endOffset = sentence.lastIndexOf("[POSP]"); } int startOffset = sentence.lastIndexOf("[CONJ]"); if (startOffset == -1) { startOffset = sentence.lastIndexOf("[PSEU]"); } if (startOffset == -1) { startOffset = sentence.lastIndexOf("[PREN]"); } if (startOffset == -1) { startOffset = sentence.lastIndexOf("[PRE_NEG]"); } if (startOffset == -1) { startOffset = sentence.lastIndexOf("[PREP]"); } if (startOffset == -1) { startOffset = 0; } sScope = sentence.substring(startOffset, endOffset); } // Classify to: negated/possible/affirmed if (sentence.contains("[NEGATED]")) { sentence = sentence + "\t" + "negated" + "\t" + sScope; } else if (sentence.contains("[POSSIBLE]")) { sentence = sentence + "\t" + "possible" + "\t" + sScope; } else { sentence = sentence + "\t" + "affirmed" + "\t" + sScope; } sToReturn = sentence; return sToReturn; }
From source file:net.jazdw.rql.parser.listfilter.ListFilter.java
@SuppressWarnings("unchecked") @Override//from w ww . j av a2s . co m public List<T> visit(ASTNode node, List<T> list) { switch (node.getName()) { case "and": for (Object obj : node) { if (obj instanceof ASTNode) { list = ((ASTNode) obj).accept(this, list); } else { throw new UnsupportedOperationException("Encountered a non-ASTNode argument in AND statement"); } } return list; case "or": Set<T> set = new LinkedHashSet<T>(); for (Object obj : node) { if (obj instanceof ASTNode) { set.addAll(((ASTNode) obj).accept(this, list)); } else { throw new UnsupportedOperationException("Encountered a non-ASTNode argument in OR statement"); } } return new ArrayList<>(set); case "eq": case "gt": case "ge": case "lt": case "le": case "ne": String propName = (String) node.getArgument(0); Object test = node.getArgumentsSize() > 1 ? node.getArgument(1) : null; List<T> result = new ArrayList<>(); for (T item : list) { Object property = getProperty(item, propName); Comparable<Object> comparableProperty; if (property instanceof Comparable) { comparableProperty = (Comparable<Object>) property; } else { throw new UnsupportedOperationException( String.format("Property '%s' is not comparable", propName)); } int comparisonValue; try { comparisonValue = comparableProperty.compareTo(test); } catch (ClassCastException e) { throw new UnsupportedOperationException( String.format("Couldn't compare '%s' to '%s'", property.toString(), test.toString())); } if (checkComparisonValue(node.getName(), comparisonValue)) { result.add(item); } } return result; case "like": case "match": propName = (String) node.getArgument(0); String matchString = (String) node.getArgument(1); Pattern matchPattern = Pattern.compile(matchString.replace("*", ".*"), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); result = new ArrayList<>(); for (T item : list) { Object property = getProperty(item, propName); String stringProperty; if (property instanceof String) { stringProperty = (String) property; } else { throw new UnsupportedOperationException( String.format("Property '%s' is not a string", propName)); } if (matchPattern.matcher(stringProperty).matches()) { result.add(item); } } return result; case "limit": int limit = (int) node.getArgument(0); int offset = node.getArgumentsSize() > 1 ? (int) node.getArgument(1) : 0; if (offset > list.size() - 1) { return Collections.emptyList(); } int toIndex = offset + limit; if (toIndex > list.size()) { toIndex = list.size(); } return list.subList(offset, toIndex); case "sort": ComparatorChain cc = new ComparatorChain(); for (Object obj : node) { String sortOption = (String) obj; boolean desc = sortOption.startsWith("-"); cc.addComparator(new BeanComparator<T>(sortOption.substring(1)), desc); } // copy the list as we are modifying it list = new ArrayList<>(list); Collections.sort(list, cc); return list; default: throw new UnsupportedOperationException( String.format("Encountered unknown operator '%s'", node.getName())); } }
From source file:fr.free.nrw.commons.Utils.java
/** * Adds extension to filename. Converts to .jpg if system provides .jpeg, adds .jpg if no extension detected * @param title File name//from w w w. j a va 2 s.c o m * @param extension Correct extension * @return File with correct extension */ public static String fixExtension(String title, String extension) { Pattern jpegPattern = Pattern.compile("\\.jpeg$", Pattern.CASE_INSENSITIVE); // People are used to ".jpg" more than ".jpeg" which the system gives us. if (extension != null && extension.toLowerCase(Locale.ENGLISH).equals("jpeg")) { extension = "jpg"; } title = jpegPattern.matcher(title).replaceFirst(".jpg"); if (extension != null && !title.toLowerCase(Locale.getDefault()).endsWith("." + extension.toLowerCase(Locale.ENGLISH))) { title += "." + extension; } // If extension is still null, make it jpg. (Hotfix for https://github.com/commons-app/apps-android-commons/issues/228) // If title has an extension in it, if won't be true if (extension == null && title.lastIndexOf(".") <= 0) { extension = "jpg"; title += "." + extension; } return title; }