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.norconex.importer.handler.tagger.impl.TextBetweenTagger.java
@Override protected void tagStringContent(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, boolean partialContent) { int flags = Pattern.DOTALL | Pattern.UNICODE_CASE; if (!caseSensitive) { flags = flags | Pattern.CASE_INSENSITIVE; }/*from w ww . j av a 2 s . co m*/ for (TextBetween between : betweens) { List<Pair<Integer, Integer>> matches = new ArrayList<Pair<Integer, Integer>>(); Pattern leftPattern = Pattern.compile(between.start, flags); Matcher leftMatch = leftPattern.matcher(content); while (leftMatch.find()) { Pattern rightPattern = Pattern.compile(between.end, flags); Matcher rightMatch = rightPattern.matcher(content); if (rightMatch.find(leftMatch.end())) { if (inclusive) { matches.add(new ImmutablePair<Integer, Integer>(leftMatch.start(), rightMatch.end())); } else { matches.add(new ImmutablePair<Integer, Integer>(leftMatch.end(), rightMatch.start())); } } else { break; } } for (int i = matches.size() - 1; i >= 0; i--) { Pair<Integer, Integer> matchPair = matches.get(i); String value = content.substring(matchPair.getLeft(), matchPair.getRight()); if (value != null) { metadata.addString(between.name, value); } } } }
From source file:com.streamreduce.core.dao.UserDAO.java
public User findUserInAccount(Account account, String name) { Query<User> query = ds.createQuery(entityClazz); query.field("account").equal(account); query.or(query.criteria("username").equal(name), query.criteria("alias").equal(Pattern.compile("^\\Q" + name + "\\E$", Pattern.CASE_INSENSITIVE))); return query.get(); }
From source file:com.github.rwitzel.streamflyer.support.ProcessEndOfStreamTest.java
protected long rewriteContent(InputStream input, OutputStream output, String encoding, boolean flush) throws IOException { Charset charset = Charset.forName(encoding); String oldPath = "something"; String newPath = "anything"; String regex = "((https?://)([^/]+/))?(" + oldPath + ")"; String replacement = "$1" + newPath; // FastRegexModifier modifier = new FastRegexModifier(regex, Pattern.CASE_INSENSITIVE | Pattern.CANON_EQ, // replacement); RegexModifier modifier = new RegexModifier(regex, Pattern.CASE_INSENSITIVE | Pattern.CANON_EQ, replacement); Reader reader = new ModifyingReader(new InputStreamReader(input, charset), modifier); Writer writer = new OutputStreamWriter(output, charset); int copied = IOUtils.copy(reader, writer); if (flush) {//from www . ja va2s .c o m writer.flush(); } return copied; }
From source file:com.taobao.common.tedis.group.DiamondConfigManager.java
public static HAConfig parseConfig(String configString) { HAConfig config = new HAConfig(); // timeout// w ww. jav a 2 s .co m 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>(); int groupSize = 0; for (String s : array) { String[] groups = s.split("\\|"); if (groupSize != 0 && groups.length != groupSize) { logger.error("group size"); } groupSize = groups.length; ServerProperties sp = new ServerProperties(); sp.servers = new ServerInfo[groupSize]; for (int i = 0; i < groupSize; i++) { String[] ss = groups[i].split(":"); ServerInfo server = new ServerInfo(); if (ss.length >= 2) { server.addr = ss[0]; 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); } sp.servers[i] = server; } 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.norconex.importer.handler.transformer.impl.StripBetweenTransformer.java
@Override protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, boolean partialContent) { int flags = Pattern.DOTALL | Pattern.UNICODE_CASE; if (!caseSensitive) { flags = flags | Pattern.CASE_INSENSITIVE; }/*from w w w .j av a2s . com*/ for (Pair<String, String> pair : stripPairs) { List<Pair<Integer, Integer>> matches = new ArrayList<Pair<Integer, Integer>>(); Pattern leftPattern = Pattern.compile(pair.getLeft(), flags); Matcher leftMatch = leftPattern.matcher(content); while (leftMatch.find()) { Pattern rightPattern = Pattern.compile(pair.getRight(), flags); Matcher rightMatch = rightPattern.matcher(content); if (rightMatch.find(leftMatch.end())) { if (inclusive) { matches.add(new ImmutablePair<Integer, Integer>(leftMatch.start(), rightMatch.end())); } else { matches.add(new ImmutablePair<Integer, Integer>(leftMatch.end(), rightMatch.start())); } } else { break; } } for (int i = matches.size() - 1; i >= 0; i--) { Pair<Integer, Integer> matchPair = matches.get(i); content.delete(matchPair.getLeft(), matchPair.getRight()); } } }
From source file:org.mybatisorm.annotation.handler.JoinHandler.java
private String getExplicitJoin(String joinHint, List<Field> fields) { StringBuilder sb = new StringBuilder(); TableHandler handler;/*from w w w .j a v a 2s. c om*/ List<Field> fieldList = new ArrayList<Field>(); Class<?> clazz; Field field; Hashtable<Set<Class<?>>, LinkedList<Field[]>> refMap = null; if (!Pattern.compile(Pattern.quote(" ON "), Pattern.CASE_INSENSITIVE).matcher(joinHint).find()) { refMap = getRefMap(fields); if (refMap.isEmpty()) throw new InvalidAnnotationException("The references for join has not been found"); } QueryTokenizer tokenizer = new QueryTokenizer(joinHint); QueryTokenizer.TokenType type; String text; boolean onRequired = false; // processing the first class type = tokenizer.next(); if (type != QueryTokenizer.TokenType.IDENTIFIER) throw new InvalidJoinException("The join hint must start with the property name."); text = tokenizer.getText(); field = getField(text); fieldList.add(field); clazz = field.getType(); handler = HandlerFactory.getHandler(clazz); sb.append(handler.getName()).append(" ").append(text).append("_"); while ((type = tokenizer.next()) != QueryTokenizer.TokenType.EOS) { text = tokenizer.getText(); switch (type) { case IDENTIFIER: field = getField(text); fieldList.add(field); clazz = field.getType(); handler = HandlerFactory.getHandler(clazz); sb.append(handler.getName()).append(" ").append(text).append("_"); onRequired = true; break; case CLASS_FIELD: String[] s = text.split("\\."); sb.append(s[0]).append("_."); field = getField(getField(s[0]).getType(), s[1]); sb.append(ColumnAnnotation.getName(field)); break; case ON: onRequired = false; sb.append(text); break; case WS: sb.append(text); break; case ETC: if (onRequired) { sb.append(getOnPhrase(fieldList, refMap)); onRequired = false; } sb.append(text); break; } } if (onRequired) { sb.append(getOnPhrase(fieldList, refMap)); } return sb.toString(); }
From source file:fr.dudie.acrachilisync.utils.IssueDescriptionReaderTest.java
/** * Generates the test dataset./*from w ww . j av a 2 s .c o m*/ * <p> * List all files under classpath:/files/description_[ko]{2}_.*.txt. * * @return the test dataset * @throws URISyntaxException * urisyntexception */ @Parameters public static List<Object[]> data() throws URISyntaxException { final File files = new File(MD5UtilsTest.class.getResource("/files").toURI()); final Pattern p = Pattern.compile("descriptionreader_[ko]{2}_.*\\.txt", Pattern.CASE_INSENSITIVE); final FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { final Matcher m = p.matcher(name); return m.matches(); } }; final List<Object[]> data = new ArrayList<Object[]>(); for (final File f : files.listFiles(filter)) { data.add(new Object[] { f, !f.getName().startsWith("descriptionreader_ok") }); } return data; }
From source file:edu.cmu.lti.oaqa.annographix.solr.SolrEvalUtils.java
public static void saveEvalResults(String questionTemplate, String topicId, SolrRes[] results, ArrayList<String> allKeyWords, String docDirName, int maxNum) throws Exception { File docRootDir = new File(docDirName); if (!docRootDir.exists()) { if (!docRootDir.mkdir()) throw new Exception("Cannot create: " + docRootDir.getAbsolutePath()); }//from www . j a v a 2 s. co m String docDirPrefix = docDirName + "/" + topicId; File docDir = new File(docDirPrefix); if (!docDir.exists()) { if (!docDir.mkdir()) throw new Exception("Cannot create: " + docDir.getAbsolutePath()); } // Let's precompile replacement regexps Pattern[] replReg = new Pattern[allKeyWords.size()]; String[] replRepl = new String[allKeyWords.size()]; for (int i = 0; i < allKeyWords.size(); ++i) { replReg[i] = Pattern.compile("(^| )(" + allKeyWords.get(i) + ")( |$)", Pattern.CASE_INSENSITIVE); replRepl[i] = "$1<b>$2</b>$3"; } for (int docNum = 0; docNum < Math.min(results.length, maxNum); ++docNum) { String docId = results[docNum].mDocId; ArrayList<String> docText = results[docNum].mDocText; StringBuilder sb = new StringBuilder(); sb.append("<html><body><br>"); sb.append("<p><i>" + questionTemplate + "</i></p><hr><br>"); for (String s : docText) { for (int k = 0; k < replReg.length; ++k) { while (true) { /* * When words share a space, the replacement will not work in the first pass * Imagine you have * word1 word2 * And both words need to be replaced. In the first pass, only * word1 is replaced. */ String sNew = replReg[k].matcher(s).replaceAll(replRepl[k]); if (sNew.equals(s)) break; s = sNew; } } sb.append(s); sb.append("<br>"); } sb.append("</body></html>"); String text = sb.toString(); File df = new File(docDirPrefix + "/" + docId + ".html"); // Don't overwrite docs! if (!df.exists()) { try { FileUtils.write(df, text); } catch (IOException e) { throw new Exception("Cannot write to file: " + df.getAbsolutePath() + " reason: " + e); } } else { System.out.println(String.format("WARNING: ignoring already created document for topic %s docId %s", topicId, docId)); } } }
From source file:com.microsoft.tfs.core.clients.versioncontrol.internal.fileattributes.FileAttributesEntry.java
/** * Compiles a filename expression into a {@link Pattern} using the regex * flags appropriate for a file attributes entry. * * @param filenameExpression//from w w w .j a v a2 s.c om * the filename expression to compile. * @return the compiled pattern. * @throws PatternSyntaxException * if the regular expression could not be compiled. */ private Pattern compilePattern(final String filenameExpression) { return Pattern.compile(filenameExpression, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); }