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.parse.OfflineQueryLogic.java
/** * Matches $regex constraints./* w w w . java 2 s. co m*/ */ private static boolean matchesRegexConstraint(Object constraint, Object value, String options) throws ParseException { if (value == null || value == JSONObject.NULL) { return false; } if (options == null) { options = ""; } if (!options.matches("^[imxs]*$")) { throw new ParseException(ParseException.INVALID_QUERY, String.format("Invalid regex options: %s", options)); } int flags = 0; if (options.contains("i")) { flags = flags | Pattern.CASE_INSENSITIVE; } if (options.contains("m")) { flags = flags | Pattern.MULTILINE; } if (options.contains("x")) { flags = flags | Pattern.COMMENTS; } if (options.contains("s")) { flags = flags | Pattern.DOTALL; } String regex = (String) constraint; Pattern pattern = Pattern.compile(regex, flags); Matcher matcher = pattern.matcher((String) value); return matcher.find(); }
From source file:org.eclipse.mylyn.internal.web.tasks.WebRepositoryConnector.java
public static IStatus performQuery(String resource, String regexp, String taskPrefix, IProgressMonitor monitor, TaskDataCollector resultCollector, TaskRepository repository) { NamedPattern p = new NamedPattern(regexp, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE | Pattern.CANON_EQ); Matcher matcher = p.matcher(resource); if (!matcher.find()) { return Status.OK_STATUS; } else {/*from ww w. ja va 2 s . c o m*/ boolean isCorrect = true; do { if (p.getGroups().isEmpty()) { // "classic" mode, no named patterns if (matcher.groupCount() < 2) { isCorrect = false; } if (matcher.groupCount() >= 1) { String id = matcher.group(1); String description = matcher.groupCount() > 1 ? cleanup(matcher.group(2), repository) : null; description = unescapeHtml(description); TaskData data = createTaskData(repository, id); TaskMapper mapper = new TaskMapper(data, true); mapper.setCreationDate(DEFAULT_DATE); mapper.setTaskUrl(taskPrefix + id); mapper.setSummary(description); mapper.setValue(KEY_TASK_PREFIX, taskPrefix); resultCollector.accept(data); } } else { String id = p.group("Id", matcher); //$NON-NLS-1$ String description = p.group("Description", matcher); //$NON-NLS-1$ if (id == null || description == null) { isCorrect = false; } if (id != null) { description = unescapeHtml(description); String owner = unescapeHtml(cleanup(p.group("Owner", matcher), repository)); //$NON-NLS-1$ String type = unescapeHtml(cleanup(p.group("Type", matcher), repository)); //$NON-NLS-1$ TaskData data = createTaskData(repository, id); TaskMapper mapper = new TaskMapper(data, true); mapper.setCreationDate(DEFAULT_DATE); mapper.setTaskUrl(taskPrefix + id); mapper.setSummary(description); mapper.setValue(KEY_TASK_PREFIX, taskPrefix); mapper.setOwner(owner); mapper.setTaskKind(type); String status = p.group("Status", matcher); //$NON-NLS-1$ if (status != null) { if (COMPLETED_STATUSES.contains(status.toLowerCase())) { // TODO set actual completion date here mapper.setCompletionDate(DEFAULT_DATE); } } resultCollector.accept(data); } } } while (matcher.find() && !monitor.isCanceled()); if (isCorrect) { return Status.OK_STATUS; } else { return new Status(IStatus.ERROR, TasksWebPlugin.ID_PLUGIN, IStatus.ERROR, Messages.WebRepositoryConnector_Require_two_matching_groups, null); } } }
From source file:org.apache.hadoop.metrics2.sink.RollingFileSystemSinkTestBase.java
/** * Assert that the given contents match what is expected from the test * metrics.// ww w.j a v a 2s . co m * * @param contents the file contents to test */ protected void assertMetricsContents(String contents) { // Note that in the below expression we allow tags and metrics to go in // arbitrary order, but the records must be in order. final Pattern expectedContentPattern = Pattern.compile("^\\d+\\s+test1.testRecord1:\\s+Context=test1,\\s+" + "(testTag1=testTagValue1,\\s+testTag2=testTagValue2|" + "testTag2=testTagValue2,\\s+testTag1=testTagValue1)," + "\\s+Hostname=.*,\\s+" + "(testMetric1=1,\\s+testMetric2=2|testMetric2=2,\\s+testMetric1=1)" + "[\\n\\r]*^\\d+\\s+test1.testRecord2:\\s+Context=test1," + "\\s+testTag22=testTagValue22,\\s+Hostname=.*$[\\n\\r]*", Pattern.MULTILINE); assertTrue("Sink did not produce the expected output. Actual output was: " + contents, expectedContentPattern.matcher(contents).matches()); }
From source file:by.stub.yaml.stubs.StubRequest.java
private boolean regexMatch(final String dataStoreValue, final String thisAssertingValue, final String templateTokenName) { try {/* w w w. jav a 2 s . c om*/ // Pattern.MULTILINE changes the behavior of '^' and '$' characters, // it does not mean that newline feeds and carriage return will be matched by default // You need to make sure that you regex pattern covers both \r (carriage return) and \n (linefeed). // It is achievable by using symbol '\s+' which covers both \r (carriage return) and \n (linefeed). final Matcher matcher = Pattern.compile(dataStoreValue, Pattern.MULTILINE).matcher(thisAssertingValue); final boolean isMatch = matcher.matches(); if (isMatch) { // group(0) holds the full regex match regexGroups.put(StringUtils.buildToken(templateTokenName, 0), matcher.group(0)); //Matcher.groupCount() returns the number of explicitly defined capturing groups in the pattern regardless // of whether the capturing groups actually participated in the match. It does not include matcher.group(0) final int groupCount = matcher.groupCount(); if (groupCount > 0) { for (int idx = 1; idx <= groupCount; idx++) { regexGroups.put(StringUtils.buildToken(templateTokenName, idx), matcher.group(idx)); } } } return isMatch; } catch (PatternSyntaxException e) { return dataStoreValue.equals(thisAssertingValue); } }
From source file:org.opennms.netmgt.syslogd.ConvertToEvent.java
private static Pattern getPattern(final String expression) { final Pattern msgPat = CACHED_PATTERNS.get(expression); if (msgPat == null) { try {/*from w w w . ja va2 s .c o m*/ final Pattern newPat = Pattern.compile(expression, Pattern.MULTILINE); CACHED_PATTERNS.put(expression, newPat); return newPat; } catch (final PatternSyntaxException pse) { LOG.warn("Failed to compile regex pattern '{}'", expression, pse); } } return msgPat; }
From source file:ca.uqac.info.monitor.BeepBeepMonitor.java
/** * Parses optional metadata that can be found in a formula's input file. * The metadata must appear in the comment lines (those beginning with * a "#" symbol) and must be of the form: * <pre>/*from ww w .ja v a 2s. c o m*/ * # @Param("some value"); * </pre> * where Param is some (user-defined) parameter name. Parameters may * span multiple lines, which still must each begin with the comment * symbol, as follows: * <pre> * # @Param("some value * # that spans multiple lines"); * </pre> * The "#" and extraneous spaces are removed on parsing. Currently BeepBeep * uses the parameter "Caption", if present, to display a name for each * monitor. All other parameters are presently ignored. * @param file_contents The string contents of the formula file * @return A map associating parameters to values */ public static Map<String, String> getMetadata(String fileContents) { Map<String, String> out_map = new HashMap<String, String>(); StringBuilder comment_contents = new StringBuilder(); Pattern pat = Pattern.compile("^\\s*?#(.*?)$", Pattern.MULTILINE); Matcher mat = pat.matcher(fileContents); while (mat.find()) { String line = mat.group(1).trim(); comment_contents.append(line).append(" "); } pat = Pattern.compile("@(\\w+?)\\((.*?)\\);"); mat = pat.matcher(comment_contents); while (mat.find()) { String key = mat.group(1); String val = mat.group(2).trim(); if (val.startsWith("\"") && val.endsWith("\"")) { // Trim double quotes if any val = val.substring(1, val.length() - 1); } out_map.put(key, val); } return out_map; }
From source file:com.thoughtworks.go.config.materials.git.GitMaterialUpdaterTest.java
@Test public void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception { GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(); submoduleRepos.addSubmodule(SUBMODULE, "sub1"); GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true); updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed); Matcher matcher = Pattern .compile(".*^\\s[a-f0-9A-F]{40} sub1 \\(heads/master\\)$.*", Pattern.MULTILINE | Pattern.DOTALL) .matcher(console.output());//from w ww .j a v a2s .co m assertThat(matcher.matches(), Matchers.is(true)); }
From source file:org.hyperic.hq.plugin.postgresql.PostgreSQLServerDetector.java
private String getConfiguration(String regex, String config) { String res = ""; Matcher m = Pattern.compile(regex, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE).matcher(config); if (m.find()) { res = m.group(1).trim();/*from w w w . j ava 2s . c o m*/ res = res.replaceAll("=", ""); res = res.replaceAll("'", ""); res = res.replaceAll("\"", ""); } return res.trim(); }
From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java
private void paintQuotes() { Pattern pattern = Pattern.compile("^>[^>].*?$", Pattern.MULTILINE); Matcher matcher = pattern.matcher(builder); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); builder.setSpan(new QuoteSpan(), start, end, 0); }//from ww w . java 2s .c o m }
From source file:ru.runa.common.web.HTMLUtils.java
private static Pattern getPatternForTag(String tagName) { final String pattern = "<\\s*%s(\\s+.*>|>)"; if (!patternForTagCache.containsKey(tagName)) { patternForTagCache.put(tagName, Pattern.compile(String.format(pattern, tagName), Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL)); }/*from w ww . j a v a 2s. c om*/ return patternForTagCache.get(tagName); }