List of usage examples for java.util.regex Pattern MULTILINE
int MULTILINE
To view the source code for java.util.regex Pattern MULTILINE.
Click Source Link
From source file:org.zaproxy.zap.spider.SpiderParam.java
/** * Parses the skip url string./* w w w .j ava 2 s .c om*/ * * @param skipURL the skip url string */ private void parseSkipURL(String skipURL) { patternSkipURL = null; if (skipURL == null || skipURL.equals("")) { return; } skipURL = skipURL.replaceAll("\\.", "\\\\."); skipURL = skipURL.replaceAll("\\*", ".*?").replaceAll("(\\s+$)|(^\\s+)", ""); skipURL = "\\A(" + skipURL.replaceAll("\\s+", "|") + ")"; patternSkipURL = Pattern.compile(skipURL, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); }
From source file:com.gs.obevo.dbmetadata.impl.dialects.AbstractDbMetadataManagerIT.java
public static String[] splitSql(String filePath) throws Exception { String sqlContent = pathToString(filePath); Pattern splitter = Pattern.compile("(?i)^GO$", Pattern.MULTILINE); return splitter.split(sqlContent); }
From source file:de.undercouch.bson4jackson.BsonGenerator.java
/** * Converts a a Java flags word into a BSON options pattern * * @param flags the Java flags// w w w . java2 s .c o m * @return the regex options string */ protected String flagsToRegexOptions(int flags) { StringBuilder options = new StringBuilder(); if ((flags & Pattern.CASE_INSENSITIVE) != 0) { options.append("i"); } if ((flags & Pattern.MULTILINE) != 0) { options.append("m"); } if ((flags & Pattern.DOTALL) != 0) { options.append("s"); } if ((flags & Pattern.UNICODE_CASE) != 0) { options.append("u"); } return options.toString(); }
From source file:com.thoughtworks.go.config.CachedGoConfigIntegrationTest.java
@Test public void shouldFailWhenTryingToAddPipelineWithTheSameNameAsAnotherPipelineDefinedRemotely_FullConfigSave() throws Exception { assertThat(configWatchList.getCurrentConfigRepos().size()).isEqualTo(1); repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestModification);//from w ww .j av a 2s .c om assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("pipe1"))).isTrue(); final PipelineConfig dupPipelineConfig = PipelineMother .twoBuildPlansWithResourcesAndSvnMaterialsAtUrl("pipe1", "ut", "www.spring.com"); try { goConfigDao.updateConfig(new UpdateConfigCommand() { @Override public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception { cruiseConfig.getGroups().first().add(dupPipelineConfig); return cruiseConfig; } }); fail("Should have thrown"); } catch (RuntimeException ex) { String errorMessage = ex.getMessage(); assertThat(errorMessage).contains( "You have defined multiple pipelines named 'pipe1'. Pipeline names must be unique. Source(s):"); Matcher matcher = Pattern.compile("^.*\\[(.*),\\s(.*)\\].*$", Pattern.DOTALL | Pattern.MULTILINE) .matcher(errorMessage); assertThat(matcher.matches()).isTrue(); assertThat(matcher.groupCount()).isEqualTo(2); PipelineConfig pipe1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("pipe1")); List<String> expectedSources = asList(dupPipelineConfig.getOriginDisplayName(), pipe1.getOriginDisplayName()); List<String> actualSources = new ArrayList<>(); for (int i = 1; i <= matcher.groupCount(); i++) { actualSources.add(matcher.group(i)); } assertThat(actualSources.size()).isEqualTo(expectedSources.size()); assertThat(actualSources.containsAll(expectedSources)).isTrue(); } }
From source file:com.github.mavenplugins.doctest.ReportMojo.java
/** * Gets the javadoc comment situated over a doctest method. *//*from ww w . j a v a2s . co m*/ protected String getJavaDoc(String source, String method) { Pattern methodPattern = Pattern.compile( "public\\s+void\\s+" + method + "\\s*\\((HttpResponse|" + HttpResponse.class.getName().replaceAll("\\.", "\\\\.") + ")", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher matcher = methodPattern.matcher(source); int start, tmp, last, comment; String doc; if (matcher.find()) { start = matcher.start(); last = -1; matcher = ANY_METHOD_FINDER.matcher(source); while (matcher.find() && (tmp = matcher.start()) < start) { last = tmp; } comment = source.lastIndexOf("/**", start); if (comment > 2 && (comment > last || last == -1)) { doc = source.substring(comment, source.indexOf("*/", comment)); doc = doc.substring(3, doc.length() - 2); doc = JAVADOC_EMPTYLINE_FINDER.matcher(doc).replaceAll(LINE_SEPARATOR); doc = JAVADOC_STAR_FINDER.matcher(doc).replaceAll(""); doc = StringUtils.replace(doc, " ", " "); doc = StringUtils.replace(doc, LINE_SEPARATOR, "<br/>"); return doc; } } return ""; }
From source file:gtu._work.ui.RegexReplacer.java
/** * @param fromPattern//from ww w . j a va 2 s . co m * ???pattern * @param toFormat * ??pattern * @param replaceText * ?? */ String replacer(String fromPattern, String toFormat, String replaceText) { String errorRtn = replaceText.toString(); try { int patternFlag = 0; // if (multiLineCheckBox.isSelected()) { patternFlag = Pattern.DOTALL | Pattern.MULTILINE; } Pattern pattern = Pattern.compile(fromPattern, patternFlag); Matcher matcher = pattern.matcher(replaceText); StringBuffer sb = new StringBuffer(); String tempStr = null; TradeOffConfig config = this.getTradeOffConfig(); { int startPos = 0; for (; matcher.find();) { tempStr = toFormat.toString(); sb.append(replaceText.substring(startPos, matcher.start())); // ---------------------------------------------- if (StringUtils.isBlank(config.fremarkerKey)) { // regex for (int ii = 0; ii <= matcher.groupCount(); ii++) { System.out.println(ii + " -- " + matcher.group(ii)); tempStr = tempStr.replaceAll("#" + ii + "#", Matcher.quoteReplacement(matcher.group(ii))); } } else if (StringUtils.isNotBlank(config.fremarkerKey)) { // freemarker Map<String, Object> root = new HashMap<String, Object>(); TreeMap<Integer, Object> lstMap = new TreeMap<Integer, Object>(); for (int ii = 0; ii <= matcher.groupCount(); ii++) { lstMap.put(ii, matcher.group(ii)); } root.put(StringUtils.trimToEmpty(config.fremarkerKey), lstMap.values()); System.out.println("template Map : " + root); tempStr = FreeMarkerSimpleUtil.replace(tempStr, root); } // ---------------------------------------------- sb.append(tempStr); startPos = matcher.end(); } sb.append(replaceText.substring(startPos)); } return sb.toString(); } catch (Exception ex) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(ex.getMessage(), getTitle()); return errorRtn; } }
From source file:fr.natoine.html.HTMLPage.java
public String deleteCommentsNewLine(String _wip_css, String _new_englobing_div) { if (_wip_css == null || _wip_css.length() == 0) return ""; // Create a pattern to match comments //Pattern p = Pattern.compile("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)", Pattern.MULTILINE); Pattern p = Pattern.compile("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)", Pattern.MULTILINE); Matcher m = p.matcher(""); m.reset(_wip_css);/*from w w w . j av a 2 s.com*/ String result = m.replaceAll(""); // Create a pattern to match all new lines and all tabs p = Pattern.compile("(\n)|(\t)"); m = p.matcher(""); m.reset(result); result = m.replaceAll(""); // Create a pattern to match all multiple " " p = Pattern.compile(" (?= )|(?<= ) "); m = p.matcher(""); m.reset(result); result = m.replaceAll(" "); //creates a pattern to match all } p = Pattern.compile("}"); m = p.matcher(""); m.reset(result); result = m.replaceAll("} #" + _new_englobing_div + " "); int cpt_last_spaces_index = result.length(); while (cpt_last_spaces_index > 0 && result.charAt(cpt_last_spaces_index - 1) == ' ') { cpt_last_spaces_index--; } result = result.substring(0, cpt_last_spaces_index); if (result.endsWith("#" + _new_englobing_div)) result = result.substring(0, result.lastIndexOf("#" + _new_englobing_div)); result = ("#" + _new_englobing_div + " ").concat(result); return result; }
From source file:pivotal.au.se.gemfirexdweb.controller.QueryController.java
private String[] spiltQuery(String query) { Pattern pattern = Pattern.compile(";\\s", Pattern.MULTILINE); String[] splitQueryStr = pattern.split(query); logger.debug("split query = {" + Arrays.toString(splitQueryStr) + "}"); return splitQueryStr; }
From source file:org.parosproxy.paros.db.TableHistory.java
public List<Integer> getHistoryList(long sessionId, int histType, String filter, boolean isRequest) throws SQLException { PreparedStatement psReadSearch = getConnection().prepareStatement( "SELECT * FROM HISTORY WHERE " + SESSIONID + " = ? AND " + HISTTYPE + " = ? ORDER BY " + HISTORYID); ResultSet rs = null;/* w w w .j a va 2s. c om*/ Vector<Integer> v = new Vector<>(); try { Pattern pattern = Pattern.compile(filter, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); Matcher matcher = null; psReadSearch.setLong(1, sessionId); psReadSearch.setInt(2, histType); rs = psReadSearch.executeQuery(); while (rs.next()) { if (isRequest) { matcher = pattern.matcher(rs.getString(REQHEADER)); if (matcher.find()) { // ZAP: Changed to use the method Integer.valueOf. v.add(Integer.valueOf(rs.getInt(HISTORYID))); continue; } matcher = pattern.matcher(rs.getString(REQBODY)); if (matcher.find()) { // ZAP: Changed to use the method Integer.valueOf. v.add(Integer.valueOf(rs.getInt(HISTORYID))); continue; } } else { matcher = pattern.matcher(rs.getString(RESHEADER)); if (matcher.find()) { // ZAP: Changed to use the method Integer.valueOf. v.add(Integer.valueOf(rs.getInt(HISTORYID))); continue; } matcher = pattern.matcher(rs.getString(RESBODY)); if (matcher.find()) { // ZAP: Changed to use the method Integer.valueOf. v.add(Integer.valueOf(rs.getInt(HISTORYID))); continue; } } } } finally { if (rs != null) { try { rs.close(); } catch (Exception e) { // Ignore } } psReadSearch.close(); } return v; }
From source file:com.ikanow.infinit.e.data_model.store.config.source.SourcePojo.java
public static void initSearchIndexFilter(SourceSearchIndexFilter searchIndexFilter) { if (null != searchIndexFilter) { // Initialize regex if ((null != searchIndexFilter.assocFilter) && (null == searchIndexFilter.assocFilterRegex)) { if (searchIndexFilter.assocFilter.startsWith("+") || searchIndexFilter.assocFilter.startsWith("-")) { searchIndexFilter.assocFilterRegex = Pattern.compile(searchIndexFilter.assocFilter.substring(1), Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); } else { searchIndexFilter.assocFilterRegex = Pattern.compile(searchIndexFilter.assocFilter, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); }//from www . j a v a2s.com } if ((null != searchIndexFilter.assocGeoFilter) && (null == searchIndexFilter.assocGeoFilterRegex)) { if (searchIndexFilter.assocGeoFilter.startsWith("+") || searchIndexFilter.assocGeoFilter.startsWith("-")) { searchIndexFilter.assocGeoFilterRegex = Pattern.compile( searchIndexFilter.assocGeoFilter.substring(1), Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); } else { searchIndexFilter.assocGeoFilterRegex = Pattern.compile(searchIndexFilter.assocGeoFilter, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); } } if ((null != searchIndexFilter.entityFilter) && (null == searchIndexFilter.entityFilterRegex)) { if (searchIndexFilter.entityFilter.startsWith("+") || searchIndexFilter.entityFilter.startsWith("-")) { searchIndexFilter.entityFilterRegex = Pattern .compile(searchIndexFilter.entityFilter.substring(1), Pattern.CASE_INSENSITIVE); } else { searchIndexFilter.entityFilterRegex = Pattern.compile(searchIndexFilter.entityFilter, Pattern.CASE_INSENSITIVE); } } if ((null != searchIndexFilter.entityGeoFilter) && (null == searchIndexFilter.entityGeoFilterRegex)) { if (searchIndexFilter.entityGeoFilter.startsWith("+") || searchIndexFilter.entityGeoFilter.startsWith("-")) { searchIndexFilter.entityGeoFilterRegex = Pattern .compile(searchIndexFilter.entityGeoFilter.substring(1), Pattern.CASE_INSENSITIVE); } else { searchIndexFilter.entityGeoFilterRegex = Pattern.compile(searchIndexFilter.entityGeoFilter, Pattern.CASE_INSENSITIVE); } } } // (end if search filter specified) }