List of usage examples for java.util.regex Matcher end
public int end()
From source file:com.norconex.importer.handler.transformer.impl.StripBeforeTransformer.java
@Override protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, boolean partialContent) { if (stripBeforeRegex == null) { LOG.error("No regular expression provided."); return;// ww w .j a v a 2 s . com } int flags = Pattern.DOTALL | Pattern.UNICODE_CASE; if (!caseSensitive) { flags = flags | Pattern.CASE_INSENSITIVE; } Pattern pattern = Pattern.compile(stripBeforeRegex, flags); Matcher match = pattern.matcher(content); if (match.find()) { if (inclusive) { content.delete(0, match.end()); } else { content.delete(0, match.start()); } } }
From source file:gtu._work.ui.LoadJspFetchJavascriptUI.java
private String writeScript(File file) throws IOException { StringBuffer sb = new StringBuffer(FileUtils.readFileToString(file, "utf8")); StringBuffer sb2 = new StringBuffer(); for (;;) {// w w w . ja va2 s . co m Matcher m1 = javascriptStart.matcher(sb.toString()); Matcher m2 = javascriptEnd.matcher(sb.toString()); if (m1.find() && m2.find()) { sb2.append(sb.substring(m1.start(), m2.end()) + "\n\n"); sb.delete(m1.start(), m2.end()); } else { break; } } return sb2.toString(); }
From source file:net.java.sip.communicator.impl.gui.main.chat.replacers.URLReplacer.java
/** * Replace operation for replacing URL's with a hyperlinked version. * * @param target destination to write the replacement result to * @param piece the piece of content to be processed *//*from ww w. ja v a 2s. c om*/ @Override public void replace(final StringBuilder target, final String piece) { final Matcher m = this.pattern.matcher(piece); int prevEnd = 0; while (m.find()) { target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd, m.start()))); prevEnd = m.end(); String url = m.group().trim(); target.append("<A href=\""); if (url.startsWith("www")) { target.append("http://"); } target.append(url); target.append("\">"); target.append(StringEscapeUtils.escapeHtml4(url)); target.append("</A>"); } target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd))); }
From source file:net.sf.zekr.engine.search.tanzil.ZeroHighlighter.java
private String getClause(String text, Matcher matcher) { int a = text.substring(0, matcher.start() + 1).lastIndexOf(' '); int b = text.indexOf(' ', matcher.end() - 1); return new String(text.substring(a + 1, b)); }
From source file:edu.cmu.lti.f12.hw2.hw2_team01.passage.CorrectedPassageCandidateFinder.java
public List<PassageCandidate> extractPassages(String[] keyterms) { String[] paragraphs = text.split("<p>"); int start = 0, end = 0; List<PassageSpan> matchedSpans = new ArrayList<PassageSpan>(); List<PassageCandidate> passageList = new ArrayList<PassageCandidate>(); // System.out.println("starting paragraph spans"); for (String paragraph : paragraphs) { start = end + 3;//from w ww.j a va 2 s.c o m end = start + paragraph.length(); // System.out.println("cleaning text..."); String cleanText = Jsoup.parse(paragraph).text().replaceAll("([\177-\377\0-\32]*)", ""); int totalKeyterms = 0; for (String keyterm : keyterms) { // System.out.println("matching keyterms..."); Pattern p = Pattern.compile(keyterm); Matcher mClean = p.matcher(cleanText); while (mClean.find()) { PassageSpan match = new PassageSpan(mClean.start(), mClean.end()); matchedSpans.add(match); totalMatches++; } if (!matchedSpans.isEmpty()) { // matchingSpans.add(matchedSpans); totalKeyterms++; } try { BioPassageCandidate pc = new BioPassageCandidate(docId, start, end, null); pc.keytermMatches = totalKeyterms; pc.addSpans(matchedSpans); pc.setText(paragraph); pcMap.put(pc, totalKeyterms); // pc.setProbablity(getScore(pc,totalmatches)); passageList.add(pc); } catch (AnalysisEngineProcessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } //System.out.println("ranking passages..."); // rank passage candidate for (PassageCandidate pc : passageList) { pc.setProbablity((float) getScore(pc, totalMatches)); } // System.out.println("ranking results"); Collections.sort(passageList, new PassageCandidateComparator()); // System.out.println("returning results"); return passageList; }
From source file:org.openmeetings.app.data.flvrecord.converter.FlvExplorerConverter.java
private FlvDimension getFlvDimension(String txt) throws Exception { Pattern p = Pattern.compile("\\d{2,4}(x)\\d{2,4}"); Matcher matcher = p.matcher(txt); while (matcher.find()) { String foundResolution = txt.substring(matcher.start(), matcher.end()); String[] resultions = foundResolution.split("x"); return new FlvDimension(Integer.valueOf(resultions[0]).intValue(), Integer.valueOf(resultions[1]).intValue()); }//from w w w . j a v a2s. co m return null; }
From source file:com.datatorrent.stram.client.StramClientUtils.java
public static void evalProperties(Properties target, Configuration vars) { ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); Pattern substitutionPattern = Pattern.compile("\\$\\{(.+?)\\}"); Pattern evalPattern = Pattern.compile("\\{% (.+?) %\\}"); try {/*from www . j av a 2 s. c om*/ engine.eval("var _prop = {}"); for (Map.Entry<String, String> entry : vars) { String evalString = String.format("_prop[\"%s\"] = \"%s\"", StringEscapeUtils.escapeJava(entry.getKey()), StringEscapeUtils.escapeJava(entry.getValue())); engine.eval(evalString); } } catch (ScriptException ex) { LOG.warn("Javascript error: {}", ex.getMessage()); } for (Map.Entry<Object, Object> entry : target.entrySet()) { String value = entry.getValue().toString(); Matcher matcher = substitutionPattern.matcher(value); if (matcher.find()) { StringBuilder newValue = new StringBuilder(); int cursor = 0; do { newValue.append(value.substring(cursor, matcher.start())); String subst = vars.get(matcher.group(1)); if (subst != null) { newValue.append(subst); } cursor = matcher.end(); } while (matcher.find()); newValue.append(value.substring(cursor)); target.put(entry.getKey(), newValue.toString()); } matcher = evalPattern.matcher(value); if (matcher.find()) { StringBuilder newValue = new StringBuilder(); int cursor = 0; do { newValue.append(value.substring(cursor, matcher.start())); try { Object result = engine.eval(matcher.group(1)); String eval = result.toString(); if (eval != null) { newValue.append(eval); } } catch (ScriptException ex) { LOG.warn("JavaScript exception {}", ex.getMessage()); } cursor = matcher.end(); } while (matcher.find()); newValue.append(value.substring(cursor)); target.put(entry.getKey(), newValue.toString()); } } }
From source file:com.projity.grouping.core.OutlineCode.java
public Object parseObject(String code, ParsePosition pos) { Object result = null;/*from w w w . j a v a2s . c o m*/ Iterator i = masks.iterator(); String current = code.substring(pos.getIndex()); Matcher matcher = pattern.matcher(current); if (matcher.matches()) { pos.setIndex(pos.getIndex() + matcher.end()); return current; } else return null; }
From source file:gate.bulstem.BulStemPR.java
private String stem(String word) { Matcher m = vocals.matcher(word); if (!m.lookingAt()) { return word; }/*from ww w. ja va2 s . c o m*/ for (int i = m.end() + 1; i < word.length(); i++) { String suffix = word.substring(i); if ((suffix = stemmingRules.get(suffix)) != null) { // get the new stem by cutting up the word and adding the right suffix // from the rules return word.substring(0, i) + suffix; } } return word; }
From source file:eu.alpinweiss.filegen.util.generator.impl.SequenceGenerator.java
String[] cropPattern(String pattern) { final String[] generationPattern = new String[3]; final Pattern compile = Pattern.compile(SEQUENCE); final Matcher matcher = compile.matcher(pattern); if (matcher.find()) { generationPattern[0] = pattern.substring(0, matcher.start()); generationPattern[1] = pattern.substring(matcher.start(), matcher.end()); generationPattern[2] = pattern.substring(matcher.end(), pattern.length()); } else {//from w ww . j av a 2s .c o m generationPattern[0] = ""; generationPattern[1] = pattern; generationPattern[2] = ""; } return generationPattern; }