List of usage examples for java.util.regex MatchResult group
public String group(int group);
From source file:Main.java
public static String url2Folder(String url) { Pattern p = Pattern.compile("android/(.*?)/"); Matcher m = p.matcher(url);//from w w w . ja v a 2 s .c o m if (m.find()) { MatchResult mr = m.toMatchResult(); return mr.group(1); } else { return null; } }
From source file:com.google.mr4c.util.CustomFormat.java
private static List<String> extractNames(String pattern) { List<String> names = new ArrayList<String>(); Scanner scanner = new Scanner(pattern); while (scanner.findWithinHorizon(VAR_REGEX, 0) != null) { MatchResult result = scanner.match(); String val = result.group(1); names.add(val); }//from ww w.j a v a 2s .c o m return names; }
From source file:de.mat.utils.pdftools.PdfMerge.java
/** * <h4>FeatureDomain:</h4>/* w ww . j a va 2 s. c o m*/ * PublishingTools * <h4>FeatureDescription:</h4> * parse bookmarks from file * <h4>FeatureResult:</h4> * <ul> * <li>returnValue lstBookMarks - list of Bookmarks (Filename, Label...) * </ul> * <h4>FeatureKeywords:</h4> * PDF Publishing * @param listFile - file with the Bookmarks * @return - list of Bookmarks * @throws Throwable */ public static List<Bookmark> parseBookMarksFromFile(String listFile) throws Throwable { // BookMarkliste aus Datei lesen List<Bookmark> lstBookMarks = new ArrayList<Bookmark>(); String fileContent = readFromFile(listFile); String[] lines = fileContent.split("\n"); if (lines != null) { // alle Zeilen durchlaufen for (int zaehler = 0; zaehler < lines.length; zaehler++) { // String line = lines[zaehler]; line = line.replace("\r", ""); line = line.replace("\n", ""); List<MatchResult> matches = findMatches(CONST_BOOKMARK, line); if (matches == null || matches.size() <= 0) { continue; } //iterate matches for (MatchResult match : matches) { // if found: add bookmark to list if (match.groupCount() == 4) { Bookmark mpBookMark = new Bookmark(); String fileName = match.group(1); fileName = fileName.replaceAll("\\+", "_"); fileName = fileName.replaceAll(">", "_"); mpBookMark.put("SRC", fileName); mpBookMark.put("NAME", match.group(2)); mpBookMark.put("TYPE", match.group(3)); mpBookMark.put("PAGE", match.group(4)); lstBookMarks.add(mpBookMark); } } } } return lstBookMarks; }
From source file:com.edgenius.wiki.render.RenderUtil.java
/** * Parse macro string and return macro name and its parameters. The value from key of WikiConstants.MACRO_NAME_KEY in return map * is macro name then with its parameters. This input suppose only has one macro (the first is parse if there are multiple macro) * and this macro doesn't be check if esacped,i.e., like \{macor} also is treat as valid macro. * If input hasn't valid macro, null is returned. * @param macro/*from ww w . j av a2 s . c o m*/ * @return */ public static Map<String, String> parseSignleMacro(String macro) { if (StringUtils.isBlank(macro)) return null; MatchResult rs = FilterRegxConstants.SINGLE_MACRO_FILTER_PATTERN.matcher(macro).toMatchResult(); int count = rs.groupCount(); if (count < 1) return null; Map<String, String> out = new HashMap<String, String>(); out.put(WikiConstants.MACRO_NAME_KEY, rs.group(1)); if (count > 1) { BaseMacroParameter params = new BaseMacroParameter(); params.setParams(rs.group(2)); out.putAll(params.getParams()); } return out; }
From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java
public LinkParts split(final MatchResult match) { String in = match.group(1); return split(in); }
From source file:com.jaxio.celerio.template.VelocityGeneratorTest.java
@Test public void testExtraction() { String message = "Object 'com.jaxio.celerio.convention.WellKnownFolder' does not contain property 'resource' at src/main/resources/spring/springmvc-parent.p.vm.xml[line " + "28, column 47]"; Scanner s = new Scanner(message); String u = s.findInLine("\\[line (\\d+), column (\\d+)\\]"); assertThat(u).isNotEmpty();/* www . j a v a 2s . c om*/ MatchResult result = s.match(); assertThat(result.groupCount()).isEqualTo(2); assertThat(result.group(1)).isEqualTo("28"); assertThat(result.group(2)).isEqualTo("47"); }
From source file:com.jaxio.celerio.template.VelocityGenerator.java
private void displayLinesInError(VelocityException exception, TemplatePack templatePack, Template template) { try {//from w w w . ja va 2 s.com Scanner scanner = new Scanner(exception.getMessage()); String match = scanner.findInLine("\\[line (\\d+), column (\\d+)\\]"); if (match == null) { return; } MatchResult result = scanner.match(); int lineInError = parseInt(result.group(1)); int column = parseInt(result.group(2)); String[] lines = template.getTemplate().split("\\n"); int linesBeforeToDisplay = 2; int linesAfterToDisplay = 2; for (int i = max(0, lineInError - linesBeforeToDisplay); i < lineInError; i++) { System.err.println(prefix(templatePack, template, i + 1) + lines[i]); } String prefix = prefix(templatePack, template, lineInError); System.err.print(prefix); for (int i = 0; i < column - 1; i++) { System.err.print(" "); } System.err.println("^"); for (int i = lineInError; i < min(lines.length - 1, lineInError + linesAfterToDisplay); i++) { System.err.println(prefix(templatePack, template, i + 1) + lines[i]); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.edgenius.wiki.render.filter.UrlFilter.java
@Override public void replace(StringBuffer buffer, MatchResult matchResult, RenderContext context) { int count = matchResult.groupCount(); if (count != 2) { buffer.append(matchResult.group(0)); return;/*from ww w . j a va2 s.c om*/ } String front = matchResult.group(1); String link = matchResult.group(2); String end = ""; Matcher m = END_PATTERN.matcher(StringUtils.reverse(link)); if (m.lookingAt()) { end = StringUtils.reverse(m.group(1)); link = link.substring(0, link.length() - end.length()); } buffer.append(formatter.format(new Object[] { front, link, end, RenderUtil.getExternalImage(context) })); }
From source file:com.edgenius.wiki.render.filter.NewlineFilter.java
@Override public void replace(StringBuffer buffer, MatchResult matchResult, RenderContext context) { String all = matchResult.group(0); // space, \t \r etc. String prefix = matchResult.group(1); //remove all \r but keep space or \t etc prefix = prefix.replaceAll("\\r", ""); buffer.append(prefix);/* w w w. j a va 2 s.c o m*/ int count = StringUtils.countMatches(all, NEWLINE); if (buffer.length() >= WikiConstants.UUID_KEY_SIZE - 1 && context .isUniqueKey(buffer.substring(buffer.length() - WikiConstants.UUID_KEY_SIZE + 1) + "\n")) { if (count == 1) { buffer.append(all); return; } else { buffer.append("\n"); count--; } } //TODO: bug: if before newline, there is a region, which will be replaced to a string. how to detect isEndByBlockHtmlTag()? //if it is after a block HTML, such as after Hr, page needn't append the first br. //if following tag is Block html tag or not, it does not matter if there are br or not. //I checked in FF3, the Block HTML tag will ignore its the first <br> before it. if (RenderUtil.isEndByBlockHtmlTag(buffer)) { count--; //TinyMCE eat "\n" //but, keep this "\n" information to render text, it is useful in RichTag render buffer.append(NEWLINE_HIDDEN_TAG).append("</span>"); } int para = count / 2; for (int idx = 0; idx < para; idx++) { if (buffer.length() == 0) { //for any empty new lines on the beginning of content, use <br> instead <p> //The reason do so, is, in rich to markup convert, first <p> at text begin will be ignore buffer.append(NEWLINE_TAG).append(NEWLINE_TAG); } else { //can not user <p class="xxx"/> to replace <p class="xxx"></p>, at least FF show wrong if use <p/> buffer.append(PARAGRAPH_TAG); } } int br = count % 2; if (br > 0) buffer.append(NEWLINE_TAG); }
From source file:edu.cmu.lti.oaqa.framework.eval.gs.KeytermGoldStandardFilePersistenceProvider.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { boolean ret = super.initialize(aSpecifier, aAdditionalParams); String dataset = (String) getParameterValue("DataSet"); Pattern lineSyntaxPattern = Pattern.compile((String) getParameterValue("LineSyntax")); try {/*from ww w . ja v a2s. co m*/ Resource[] resources = resolver.getResources((String) getParameterValue("PathPattern")); for (Resource resource : resources) { Scanner scanner = new Scanner(resource.getInputStream()); while (scanner.findInLine(lineSyntaxPattern) != null) { MatchResult result = scanner.match(); DatasetSequenceId id = new DatasetSequenceId(dataset, result.group(1)); if (!id2gsSpans.containsKey(id)) { id2gsSpans.put(id, new ArrayList<String>()); } id2gsSpans.get(id).add(result.group(4)); if (scanner.hasNextLine()) { scanner.nextLine(); } else { break; } } scanner.close(); } } catch (IOException e) { e.printStackTrace(); } return ret; }