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:com.github.rwitzel.streamflyer.regex.RegexModifierTest.java
@Test public void testExampleFromRegexModifierJavadoc_OwnMatchProcessor() throws Exception { String fakeErrorLog = "1 ERROR aa\n2 WARN bb\n3 ERROR cc"; // choose the character stream to modify Reader originalReader = new StringReader( // fakeErrorLog);/*from w ww . j a v a 2s .c o m*/ // select the modifier Modifier myModifier = new RegexModifier("^.*ERROR.*$", Pattern.MULTILINE, new MatchPrinter(), 0, 2048); // create the modifying reader that wraps the original reader Reader modifyingReader = new ModifyingReader(originalReader, myModifier); // use the modifying reader instead of the original reader String output = IOUtils.toString(modifyingReader); // stream content is not modified assertEquals(fakeErrorLog, output); }
From source file:com.groupon.jenkins.dynamic.buildconfiguration.ShellCommands.java
public Pattern regexp(String re) { int n = re.length() - 1, flags = Pattern.UNIX_LINES | Pattern.MULTILINE; if (re.charAt(0) != '^') { re = ".*" + re; }//from www. j a v a 2 s . c om if (re.charAt(n) != '$') { re = re + ".*"; } return Pattern.compile(re, flags); }
From source file:org.squale.welcom.struts.lazyLoading.WLazyUtil.java
/** * converti un select en champ input classique * // www .java 2 s. c om * @param s chaine contenant le flux modifier * @return le flux mis jour */ public static String convertSelectToLightInput(final String s) { final StringBuffer smallInput = new StringBuffer(); smallInput.append("<input "); // try { // Search name // RE reSelect=new RE("<\\s*select([^>]*)>",RE.MATCH_CASEINDEPENDENT); final Pattern reSelect = Pattern.compile("<\\s*select([^>]*)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); // RE reOptionSelected = new RE ("<\\s*option[^>]+selected[^>]*>",RE.MATCH_CASEINDEPENDENT); final Pattern reOptionSelected = Pattern.compile("<\\s*option[^>]+selected[^>]*>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); // RE reOption = new RE ("<\\s*option[^>]*>",RE.MATCH_CASEINDEPENDENT); final Pattern reOption = Pattern.compile("<\\s*option[^>]*>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher maSelect = reSelect.matcher(s); if (maSelect.find()) { Hashtable parameters = searchParameter(s); if (parameters.containsKey("name")) { smallInput.append("name="); smallInput.append(parameters.get("name")); smallInput.append(" "); } else { return s; } final Matcher maOptionSelected = reOptionSelected.matcher(s); if (maOptionSelected.find()) { parameters = searchParameter(maOptionSelected.group(0)); if (parameters.containsKey("value")) { smallInput.append("value="); smallInput.append(parameters.get("value")); } else { final int posStart = maOptionSelected.end(0); final Pattern reOptionEnd = Pattern.compile("([^<]*)<\\s*\\/option\\s*>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher maOptionEnd = reOptionEnd.matcher(s); // RE reOptionEnd= new RE ("([^<]*)<\\s*\\/option\\s*>"); if (maOptionEnd.find(posStart)) { final String value = maOptionEnd.group(1); smallInput.append("value="); smallInput.append(parameters.get("value")); } else { return s; } } } else { final Matcher maOption = reOption.matcher(s); if (maOption.find()) { parameters = searchParameter(maOption.group(0)); if (parameters.containsKey("value")) { smallInput.append("value="); smallInput.append(parameters.get("value")); } else { final int posStart = maOption.end(0); final Pattern reOptionEnd = Pattern.compile("([^<]*)<\\s*\\/option\\s*>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher maOptionEnd = reOptionEnd.matcher(s); // RE reOptionEnd= new RE ("([^<]*)<\\s*\\/option\\s*>"); if (maOptionEnd.find(posStart)) { final String value = maOptionEnd.group(1); smallInput.append("value="); smallInput.append(parameters.get("value")); } else { return s; } } } else { return s; } } } smallInput.append(">"); return smallInput.toString(); }
From source file:org.echocat.jomon.runtime.jaxb.PatternAdapter.java
@Nonnull protected String toFlagsAsString(@Nonnegative int flags) { final StringBuilder sb = new StringBuilder(); if ((flags & Pattern.CASE_INSENSITIVE) != 0) { sb.append('i'); }/*from w w w. j av a 2s.c om*/ if ((flags & Pattern.MULTILINE) != 0) { sb.append('m'); } if ((flags & Pattern.DOTALL) != 0) { sb.append('s'); } if ((flags & Pattern.COMMENTS) != 0) { sb.append('x'); } return sb.toString(); }
From source file:org.zaproxy.zap.extension.ascanrules.wpscan.java
@Override public void scan() { try {// ww w.j av a 2 s. c o m URI originalURI = this.getBaseMsg().getRequestHeader().getURI(); String target = originalURI.getScheme() + "://" + originalURI.getAuthority(); log.info("Starting wpscan... Target is " + target); log.info(target); ProcessBuilder builder = new ProcessBuilder("/usr/bin/wpscan", "--url", target); builder.redirectErrorStream(true); Process process = builder.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String fileExistsPatternString = "^\\[31m\\[!\\]\\[0m The WordPress '(.*)' file exists$"; Pattern fileExistsPattern = Pattern.compile(fileExistsPatternString, Pattern.MULTILINE); String backupExistsPatternString = "^\\[31m\\[!\\]\\[0m A (.*) backup file has been found in: '(.*)'$"; Pattern backupExistsPattern = Pattern.compile(backupExistsPatternString, Pattern.MULTILINE); String vulnWithReferencePatternString = "^\\[31m\\[!\\]\\[0m(?:Title:)? (.*)\n Reference: (.*)"; Pattern vulnWithReferencePattern = Pattern.compile(vulnWithReferencePatternString, Pattern.MULTILINE); String vulnPatternString = "^\\[31m\\[!\\]\\[0m(?: Title\\:)? (.*)"; Pattern vulnPattern = Pattern.compile(vulnPatternString); String blockDelimiterPatternString = ".*\n\n.*"; Pattern blockDelimiterPattern = Pattern.compile(blockDelimiterPatternString, Pattern.MULTILINE); String line; String buffer = ""; while ((line = reader.readLine()) != null) { buffer += line + "\n"; Matcher blockDelimiterMatcher = blockDelimiterPattern.matcher(buffer); if (blockDelimiterMatcher.find()) { // new block, process it. Matcher fileExistsMatcher = fileExistsPattern.matcher(buffer); Matcher backupExistsMatcher = backupExistsPattern.matcher(buffer); Matcher vulnWithReferenceMatcher = vulnWithReferencePattern.matcher(buffer); Matcher vulnMatcher = vulnPattern.matcher(buffer); while (fileExistsMatcher.find()) { bingo(Alert.RISK_INFO, Alert.WARNING, "WordPress installation file", "A WordPress installation is present on the server.", fileExistsMatcher.group(1), "", fileExistsMatcher.group(1), "", "These files should be removed from the server upon installation.", "Remove installation files.", getNewMsg()); } while (backupExistsMatcher.find()) { bingo(Alert.RISK_HIGH, Alert.WARNING, "WordPress " + backupExistsMatcher.group(1) + " backup file", "A WordPress configuration back file is present on the server.", backupExistsMatcher.group(2), "", backupExistsMatcher.group(2), "", "Backup files should not be accessible from the web server.", "Backup your files at a safe place that is not acessible from the web server.", getNewMsg()); } if (vulnWithReferenceMatcher.find()) { bingo(Alert.RISK_HIGH, Alert.WARNING, vulnWithReferenceMatcher.group(1), "Wordpress Vulnerability.", vulnWithReferenceMatcher.group(1), "", vulnWithReferenceMatcher.group(1), vulnWithReferenceMatcher.group(2), "", ".", getNewMsg()); } else if (vulnMatcher.find()) { bingo(Alert.RISK_HIGH, Alert.WARNING, vulnMatcher.group(1), "Wordpress Vulnerability.", vulnMatcher.group(1), "", vulnMatcher.group(1), "", "", ".", getNewMsg()); } buffer = ""; //clear buffer } } } catch (Exception e) { log.info("Error" + e.getMessage()); } }
From source file:com.gorillalogic.fonemonkey.PropertyUtil.java
/** * A better wildcard pattern matcher (written by Justin). * //from w w w . ja v a 2 s.c om * @param src * the string to search for the pattern * @param pattern * the wildcard pattern (containing * and ?) * @return true if matches, otherwise false */ private static boolean matchWildcard(String src, String pattern) { // first, escape everything in the pattern that's not a wildcard char (either * or ?) StringBuilder sb = new StringBuilder(); for (char c : pattern.toCharArray()) { if ("*?".indexOf(c) != -1) { sb.append(c); } else { // not wildcard char, so escape it sb.append("\\Q").append(c).append("\\E"); } } // 1. replace * (or repeated *'s) with .* // 2. replace ? with . pattern = sb.toString().replaceAll("\\*+", ".*").replaceAll("\\?", "."); Pattern p = Pattern.compile(pattern, Pattern.DOTALL | Pattern.MULTILINE); return p.matcher(src).matches(); }
From source file:org.projectforge.jira.JiraUtils.java
/** * Returns found matches for JIRA issues: UPPERCASE_LETTERS-###: [A-Z][A-Z_0-9]*-[0-9]+ * @param text/* ww w . java 2 s . c o m*/ * @return */ public static String[] parseJiraIssues(final String text) { if (StringUtils.isBlank(text)) { return null; } List<String> list = null; final Pattern p = Pattern.compile(PATTERN, Pattern.MULTILINE); final Matcher m = p.matcher(text); while (m.find()) { if (list == null) { list = new ArrayList<String>(); } if (m.group(1) != null) list.add(m.group(1)); } if (list == null) { return null; } final String[] result = new String[list.size()]; return (String[]) list.toArray(result); }
From source file:org.slc.sli.ingestion.util.IndexJSFileParser.java
private static Matcher ensureIndexStatement(String statement) { //# collection,uniqueness,sparse,key1:order,key2:order... Pattern ensureIndexPattern = Pattern.compile( "^db\\[\"(\\S+)\"]\\.ensureIndex\\((\\{[^}]*\\})(,\\s*\\{\\s*unique\\s*:\\s*(\\S+)\\s*\\})?\\);.*", Pattern.MULTILINE); Matcher ensureIndexMatcher = ensureIndexPattern.matcher(statement); if (ensureIndexMatcher.matches()) { return ensureIndexMatcher; }//from w w w. j ava 2 s. co m return null; }
From source file:me.doshou.admin.monitor.web.controller.JPAQLExecutorController.java
@PageableDefaults(pageNumber = 0, value = 10) @RequestMapping(value = "/ql", method = RequestMethod.POST) public String executeQL(final @RequestParam("ql") String ql, final Model model, final Pageable pageable) { model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em)); try {//from w ww .jav a 2 s . c om new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { //1?ql try { Query query = em.createQuery(ql); int updateCount = query.executeUpdate(); model.addAttribute("updateCount", updateCount); return null; } catch (Exception e) { } //2 ?ql String findQL = ql; String alias = QueryUtils.detectAlias(findQL); if (StringUtils.isEmpty(alias)) { Pattern pattern = Pattern.compile("^(.*\\s*from\\s+)(.*)(\\s*.*)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); findQL = pattern.matcher(findQL).replaceFirst("$1$2 o $3"); } String countQL = QueryUtils.createCountQueryFor(findQL); Query countQuery = em.createQuery(countQL); Query findQuery = em.createQuery(findQL); findQuery.setFirstResult(pageable.getOffset()); findQuery.setMaxResults(pageable.getPageSize()); Page page = new PageImpl(findQuery.getResultList(), pageable, (Long) countQuery.getSingleResult()); model.addAttribute("resultPage", page); return null; } }); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); model.addAttribute(Constants.ERROR, sw.toString()); } return showQLForm(); }
From source file:Repackage.java
public void repackage() throws Exception { if (_sourceBase == null || _targetBase == null) { // read from system.in, // write on system.out System.out.println(_repackager.repackage(readInputStream(System.in)).toString()); return;/*from w w w. ja v a 2 s .c o m*/ } _fromPackages = _repackager.getFromPackages(); _toPackages = _repackager.getToPackages(); _packagePattern = Pattern.compile("^\\s*package\\s+((?:\\w|\\.)*)\\s*;", Pattern.MULTILINE); _moveAlongFiles = new ArrayList(); _movedDirs = new HashMap(); // System.out.println( "Deleting repackage dir ..." ); // recursiveDelete( _targetBase ); _targetBase.mkdirs(); ArrayList files = new ArrayList(); fillFiles(files, _sourceBase); System.out.println("Repackaging " + files.size() + " files ..."); int prefixLength = _sourceBase.getCanonicalPath().length(); for (int i = 0; i < files.size(); i++) { File from = (File) files.get(i); String name = from.getCanonicalPath().substring(prefixLength + 1); repackageFile(name); } finishMovingFiles(); if (_skippedFiles > 0) System.out.println("Skipped " + _skippedFiles + " unmodified files."); }