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.sf.zekr.engine.search.tanzil.ZeroHighlighter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) protected SearchResultModel doSearch(String rawQuery) throws SearchException { try {/*w ww. j ava 2 s . c o m*/ logger.debug("Searching for query: " + rawQuery); rawQuery = rawQuery.replaceAll("\\-", "!"); boolean thisIsQuran = !quranText.isTranslation(); PatternEnricher enricher = PatternEnricherFactory.getEnricher(quranText.getLanguage(), thisIsQuran); if (thisIsQuran) { // it's translation enricher.setParameter(QuranPatternEnricher.IGNORE_HARAKA, Boolean.FALSE); } String pattern = enricher.enrich(rawQuery); String highlightPattern = pattern.replaceAll("[+!]", "|"); highlightPattern = highlightPattern.replaceAll("^[|]+", "").replaceAll("!", ""); // remove leading '|'s logger.debug("Rewritten query: " + pattern); pattern = StringUtils.replace(pattern, "!", "+!"); if (pattern.startsWith("+")) { pattern = pattern.substring(1); } String[] patterns = pattern.split("\\+"); Set<String> clauses = new LinkedHashSet<String>(); List intermediateResult = locations; for (int i = 0; i < patterns.length; i++) { // TODO: for queries with patterns.length > 1, first search for larger (more filtering) patterns[i] String p = patterns[i]; boolean exclude; if (exclude = p.charAt(0) == '!') { p = p.substring(1); } intermediateResult = filterBucket(intermediateResult, p, exclude, i == 0, enricher); } // extract matched parts and clauses int total = 0; List resultItems = intermediateResult; for (int i = 0; i < patterns.length; i++) { if (patterns[i].charAt(0) == '!') { continue; } Pattern regex = Pattern.compile(patterns[i], Pattern.CASE_INSENSITIVE); for (int j = 0; j < resultItems.size(); j++) { SearchResultItem sri = (SearchResultItem) resultItems.get(j); Matcher matcher = regex.matcher(sri.text); while (matcher.find()) { total++; sri.matchedParts.add(new String(matcher.group())); clauses.add(getClause(sri.text, matcher)); } } } // score and highlight results logger.debug("Score and highlight search results."); scoreSearchResult(resultItems, highlightPattern, patterns.length); return new SearchResultModel(quranText, resultItems, StringUtils.join(clauses, " "), rawQuery, total, searchResultComparator, ascending); } catch (SearchException se) { throw se; } catch (Exception e) { throw new SearchException(e); } }
From source file:org.ubicompforall.cityexplorer.gui.ImportWebTab_oldWebView.java
/*** * Extract database URLs from the web-page source code, given as the string text * @param text the web-page source code * @return new web-page source code with multiple "<A HREF='databaseX.sqlite'>databaseX</A>" only *///from ww w .ja va2 s . com public static void extractDBs(String text, String SERVER_URL) { //String BASE_URL = "http://www.sintef.no"; StringBuffer linkTerms = new StringBuffer(); //E.g. "(End-user Development)|(EUD)" // Find all the a href's Matcher m = Pattern.compile("<a.* href=\"([^>]+(sqlite|db|db3))\">([^<]+)</a>", Pattern.CASE_INSENSITIVE) .matcher(text); while (m.find()) { String URL = m.group(1); // group 0 is everything if (URL.charAt(0) == '/') { URL = SERVER_URL + URL; } linkTerms.append("<A HREF=\"" + URL + "\">" + m.group(3) + "</A><BR>\n"); } //linkTerms.append( "<BR><HR><BR>\n" ); //linkTerms.append( text ); //return linkTerms.toString(); }
From source file:com.liferay.ide.project.core.upgrade.UpgradeMetadataHandler.java
private String getNewDoctTypeSetting(String doctypeSetting, String newValue, String regrex) { String newDoctTypeSetting = null; Pattern p = Pattern.compile(regrex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(doctypeSetting); if (m.find()) { String oldVersionString = m.group(m.groupCount()); newDoctTypeSetting = doctypeSetting.replace(oldVersionString, newValue); }/* w w w . ja v a2 s. co m*/ return newDoctTypeSetting; }
From source file:com.wordnik.swaggersocket.server.SwaggerSocketProtocolInterceptor.java
@Override public void configure(AtmosphereConfig config) { heartbeat = config.getBroadcasterFactory().lookup(DefaultBroadcaster.class, "/swaggersocket.heartbeat"); if (heartbeat == null) { heartbeat = config.getBroadcasterFactory().get(DefaultBroadcaster.class, "/swaggersocket.heartbeat"); }/*w ww . ja va 2 s. co m*/ lazywrite = config.getInitParameter("com.wordnik.swaggersocket.protocol.lazywrite", false); emptyentity = config.getInitParameter("com.wordnik.swaggersocket.protocol.emptyentity", false); String p = config.getInitParameter("com.wordnik.swaggersocket.protocol.includedheaders"); if (p != null) { includedheaders = Pattern.compile(p, Pattern.CASE_INSENSITIVE); } p = config.getInitParameter("com.wordnik.swaggersocket.protocol.excludedheaders"); if (p != null) { excludedheaders = Pattern.compile(p, Pattern.CASE_INSENSITIVE); } }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyOnlineSyncJob.java
private String getDbPath() { String dbPath = jdbcOperations.execute(new ConnectionCallback<String>() { @Override/*from w ww .j a v a 2 s. c om*/ public String doInConnection(Connection con) throws SQLException, DataAccessException { DatabaseMetaData meta = con.getMetaData(); String url = meta.getURL(); Pattern pat = Pattern.compile("^jdbc:derby:(\\w+)", Pattern.CASE_INSENSITIVE); Matcher m = pat.matcher(url); String dbName; if (m.find()) { dbName = m.group(1); } else { log.warn("Unable to find Derby database name in connection URL: {}", url); return null; } String home = System.getProperty("derby.system.home", ""); File f = new File(home, dbName); return f.getPath(); } }); return dbPath; }
From source file:com.opensymphony.xwork2.validator.validators.RegexFieldValidator.java
public void validate(Object object) throws ValidationException { String fieldName = getFieldName(); Object value = this.getFieldValue(fieldName, object); // if there is no value - don't do comparison // if a value is required, a required validator should be added to the field String regexToUse = getRegex(); if (LOG.isDebugEnabled()) { LOG.debug("Defined regexp as [#0]", regexToUse); }//from w ww . j ava 2s. c o m if (value == null || regexToUse == null) { return; } // XW-375 - must be a string if (!(value instanceof String)) { return; } // string must not be empty String str = ((String) value).trim(); if (str.length() == 0) { return; } // match against expression Pattern pattern; if (isCaseSensitive()) { pattern = Pattern.compile(regexToUse); } else { pattern = Pattern.compile(regexToUse, Pattern.CASE_INSENSITIVE); } String compare = (String) value; if (isTrimed()) { compare = compare.trim(); } Matcher matcher = pattern.matcher(compare); if (!matcher.matches()) { addFieldError(fieldName, object); } }
From source file:gtu._work.etc.SqlReplacerUI.java
private void initGUI() { try {//from w w w . j a v a 2s . c o m BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(387, 246)); { jTextArea1 = new JTextArea(); jScrollPane1.setViewportView(jTextArea1); jTextArea1.setText(""); } } } { jPanel2 = new JPanel(); FlowLayout jPanel2Layout = new FlowLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); { replaceFromText = new JTextField(); jPanel2.add(replaceFromText); replaceFromText.setPreferredSize(new java.awt.Dimension(266, 22)); } { replaceToText = new JTextField(); jPanel2.add(replaceToText); replaceToText.setPreferredSize(new java.awt.Dimension(266, 22)); } { execute = new JButton(); jPanel2.add(execute); execute.setText("execute"); execute.setPreferredSize(new java.awt.Dimension(149, 42)); execute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String text = jTextArea1.getText(); if (StringUtils.isBlank(text)) { JCommonUtil._jOptionPane_showMessageDialog_error("area empty!"); return; } String fromTxt = replaceFromText.getText(); String toTxt = StringUtils.defaultString(replaceToText.getText()); if (StringUtils.isBlank(fromTxt)) { JCommonUtil._jOptionPane_showMessageDialog_error("fromTxt empty!"); return; } StringBuffer sb = new StringBuffer(); Pattern ptn = Pattern.compile("(.){0,1}" + fromTxt + "(.){0,1}", Pattern.CASE_INSENSITIVE); Matcher mth = null; String[] scopeStrs = { ",", " ", "(", ")", "[", "]" }; BufferedReader reader = new BufferedReader(new StringReader(text)); for (String line = null; (line = reader.readLine()) != null;) { mth = ptn.matcher(line); while (mth.find()) { String scope1 = mth.group(1); String scope2 = mth.group(2); boolean ok1 = scope1.length() == 0 || StringUtils.indexOfAny(scope1, scopeStrs) != -1; boolean ok2 = scope2.length() == 0 || StringUtils.indexOfAny(scope2, scopeStrs) != -1; if (ok1 && ok2) { mth.appendReplacement(sb, scope1 + toTxt + scope2); } } mth.appendTail(sb); sb.append("\n"); } reader.close(); jTextArea1.setText(sb.toString()); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } } } pack(); setSize(400, 300); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:TelnetTest.java
public void testFTP_Telnet_Remote_Execution_002() throws IOException { os.write("ps\r\n".getBytes()); os.flush();/*from ww w.ja v a 2 s . c om*/ String s = readUntil(is, prompt); s = s.substring(0, s.indexOf(prompt)); // System.out.println(s); 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.predic8.membrane.core.transport.ssl.SSLContextCollection.java
/** * @param sslContexts/*w ww. j a v a 2s. c o m*/ * list of SSLContext * @param dnsNames * corresponding (=same length, 1:1 mapping) list of dnsName * strings (same syntax as * {@link ServiceProxyKey#setHost(String)}) */ private SSLContextCollection(List<SSLContext> sslContexts, List<String> dnsNames) { this.dnsNames = new ArrayList<Pattern>(); for (String dnsName : dnsNames) this.dnsNames .add(Pattern.compile(ServiceProxyKey.createHostPattern(dnsName), Pattern.CASE_INSENSITIVE)); this.sslContexts = sslContexts; }
From source file:mobisocial.musubi.service.AddressBookUpdateHandler.java
static final Pattern getEmailPattern() { return Pattern.compile("\\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b", Pattern.CASE_INSENSITIVE); }