List of usage examples for java.util.regex Matcher end
public int end()
From source file:com.javielinux.utils.Utils.java
static public String toHTML(Context context, String text, String underline) { String out = text.replace("<", "<"); //out = out.replace(">", ">"); ArrayList<Integer> valStart = new ArrayList<Integer>(); ArrayList<Integer> valEnd = new ArrayList<Integer>(); Comparator<Integer> comparator = Collections.reverseOrder(); // enlaces/*from w ww . jav a 2s . c o m*/ String regex = "\\(?\\b(http://|https://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(out); while (m.find()) { valStart.add(m.start()); valEnd.add(m.end()); } // hashtag regex = "(#[\\w-]+)"; p = Pattern.compile(regex); m = p.matcher(out); while (m.find()) { valStart.add(m.start()); valEnd.add(m.end()); } // usuarios twitter regex = "(@[\\w-]+)"; p = Pattern.compile(regex); m = p.matcher(out); while (m.find()) { valStart.add(m.start()); valEnd.add(m.end()); } ThemeManager theme = new ThemeManager(context); String tweet_color_link = theme.getStringColor("tweet_color_link"); String tweet_color_hashtag = theme.getStringColor("tweet_color_hashtag"); String tweet_color_user = theme.getStringColor("tweet_color_user"); Collections.sort(valStart, comparator); Collections.sort(valEnd, comparator); for (int i = 0; i < valStart.size(); i++) { int s = valStart.get(i); int e = valEnd.get(i); String link = out.substring(s, e); if (link.equals(underline)) { link = "<u>" + out.substring(s, e) + "</u>"; } if (out.substring(s, s + 1).equals("#")) { out = out.substring(0, s) + "<font color=\"#" + tweet_color_hashtag + "\">" + link + "</font>" + out.substring(e, out.length()); } else if (out.substring(s, s + 1).equals("@")) { out = out.substring(0, s) + "<font color=\"#" + tweet_color_user + "\">" + link + "</font>" + out.substring(e, out.length()); } else { out = out.substring(0, s) + "<font color=\"#" + tweet_color_link + "\">" + link + "</font>" + out.substring(e, out.length()); } } return out; }
From source file:es.uvigo.ei.sing.adops.views.TextFileViewer.java
private void updateSearch() { textArea.getHighlighter().removeAllHighlights(); final String textToFind = txtSearch.getText(); if (!textToFind.isEmpty()) { final String text = textArea.getText(); if (this.chkRegularExpression.isSelected()) { try { final Pattern pattern = Pattern.compile(textToFind); this.txtSearch.setBackground(Color.WHITE); final Matcher matcher = pattern.matcher(text); while (matcher.find()) { try { textArea.getHighlighter().addHighlight(matcher.start(), matcher.end(), highlightPatiner); } catch (BadLocationException e1) { e1.printStackTrace(); }/*w ww . j a v a2 s. c om*/ } } catch (PatternSyntaxException pse) { this.txtSearch.setBackground(Color.RED); } } else { final int textToFindLength = textToFind.length(); int index = 0; while ((index = text.indexOf(textToFind, index)) != -1) { try { textArea.getHighlighter().addHighlight(index, index + textToFindLength, highlightPatiner); index += textToFindLength + 1; } catch (BadLocationException e1) { e1.printStackTrace(); } } } } }
From source file:edu.cmu.lti.f12.hw2.hw2_team01.passage.SentenceBasedPassageCandidateFinder.java
public List<PassageCandidate> extractPassages(String[] keyterms) { // String[] paragraphs = text.split("<P>"); List<PassageSpan> paragraphs = splitParagraph(text); int start = 0, end = 0; List<PassageSpan> matchedSpans = new ArrayList<PassageSpan>(); List<PassageCandidate> passageList = new ArrayList<PassageCandidate>(); // System.out.println("starting paragraph spans"); Iterator<PassageSpan> iparagprah = paragraphs.iterator(); String paragraph = new String(); PassageSpan ps;// w w w . j av a2s.c om for (String keyterm : keyterms) { Pattern p = Pattern.compile(keyterm.toLowerCase()); Matcher m = p.matcher(text.toLowerCase()); while (m.find()) { PassageSpan match = new PassageSpan(m.start(), m.end()); matchedSpans.add(match); totalMatches++; } if (!matchedSpans.isEmpty()) { totalKeyterms++; } } while (iparagprah.hasNext()) { ps = iparagprah.next(); paragraph = text.substring(ps.begin, ps.end); start = ps.begin; end = ps.end; // System.out.println("cleaning text..."); String cleanText = Jsoup.parse(paragraph).text().replaceAll("([\177-\377\0-\32]*)", ""); int keytermsFound = 0; int matchednum = 0; for (String keyterm : keyterms) { // System.out.println("matching keyterms..."); Pattern p = Pattern.compile(keyterm.toLowerCase()); Matcher mClean = p.matcher(cleanText.toLowerCase()); while (mClean.find()) { PassageSpan match = new PassageSpan(mClean.start(), mClean.end()); matchedSpans.add(match); matchednum++; } if (!matchedSpans.isEmpty()) { // matchingSpans.add(matchedSpans); keytermsFound++; } } if (matchednum != 0) { double score = scorer.scoreWindow(start, end, matchednum, totalMatches, keytermsFound, totalKeyterms, textSize); try { BioPassageCandidate pc = new BioPassageCandidate(docId, start, end, (float) score, null); pc.keytermMatches = keytermsFound; pc.setText(paragraph); passageList.add(pc); } catch (AnalysisEngineProcessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return passageList; }
From source file:com.haulmont.cuba.core.global.QueryParserRegex.java
@Override public boolean hasIsNullCondition(String attribute) { Matcher whereMatcher = WHERE_PATTERN.matcher(source); if (whereMatcher.find()) { String alias = getEntityAlias(); Pattern isNullPattern = Pattern.compile("\\b" + alias + "\\." + attribute + "((?i)\\s+is\\s+null)\\b"); Matcher isNullMatcher = isNullPattern.matcher(source); return isNullMatcher.find(whereMatcher.end()); }//www . j av a2 s . c o m return false; }
From source file:com.haulmont.cuba.core.global.QueryTransformerRegex.java
@Override public void mergeWhere(String query) { int startPos = 0; Matcher whereMatcher = WHERE_PATTERN.matcher(query); if (whereMatcher.find()) startPos = whereMatcher.end() + 1; int endPos = query.length(); Matcher lastClauseMatcher = LAST_CLAUSE_PATTERN.matcher(query); if (lastClauseMatcher.find()) endPos = lastClauseMatcher.start(); addWhere(query.substring(startPos, endPos)); }
From source file:de.micromata.genome.gwiki.plugin.confluenceimporter_1_0.confluence.ConfluenceImporter.java
protected String patchInternalLinks(GWikiContext wikiContext, String body, String pathPrefix) { String regexp = "\\[([^\n]+?)\\]"; Pattern p = Pattern.compile(regexp); Matcher m = p.matcher(body); StringBuilder sb = new StringBuilder(); int lastEnd = 0; while (m.find() == true) { int start = m.start(); int end = m.end(); sb.append(body.subSequence(lastEnd, start)); String linkb = m.group(1); lastEnd = end;/* ww w . j av a2 s . co m*/ sb.append("[").append(patchLinkBody(wikiContext, linkb, pathPrefix)).append("]"); } sb.append(body.substring(lastEnd)); return sb.toString(); }
From source file:hudson.Util.java
/** * Replaces the occurrence of '$key' by <tt>resolver.get('key')</tt>. * * <p>//from www. jav a 2s. c o m * Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.) */ public static String replaceMacro(String s, VariableResolver<String> resolver) { if (s == null) { return null; } int idx = 0; while (true) { Matcher m = VARIABLE.matcher(s); if (!m.find(idx)) return s; String key = m.group().substring(1); // escape the dollar sign or get the key to resolve String value; if (key.charAt(0) == '$') { value = "$"; } else { if (key.charAt(0) == '{') key = key.substring(1, key.length() - 1); value = resolver.resolve(key); } if (value == null) idx = m.end(); // skip this else { s = s.substring(0, m.start()) + value + s.substring(m.end()); idx = m.start() + value.length(); } } }
From source file:it.drwolf.ridire.session.async.JobDBDataUpdater.java
private String[] getJobsArray() throws HttpException, IOException, SAXException, XPathExpressionException { if (this.getCrawlerEngineStatus().equals(CrawlerManager.STOPPED)) { return new String[] {}; }//from w ww. j a v a 2 s . c om HttpMethod method = null; List<String> ret = new ArrayList<String>(); try { method = new PostMethod(this.engineUri); // method.setFollowRedirects(true); ((PostMethod) method).addParameter(new NameValuePair("action", "rescan")); // TODO check status code int status = this.httpClient.executeMethod(method); method.releaseConnection(); method = new GetMethod(this.engineUri); status = this.httpClient.executeMethod(method); String body = method.getResponseBodyAsString(); Matcher m = CrawlerManager.pJob.matcher(body); int start = 0; while (m.find(start)) { ret.add(m.group(1)); start = m.end(); } method.releaseConnection(); } finally { if (method != null) { method.releaseConnection(); } } return ret.toArray(new String[ret.size()]); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.WarningValue.java
protected void consumeHostPort() { Matcher m = HOSTPORT_PATTERN.matcher(src.substring(offs)); if (!m.find()) parseError();/*w w w .j a v a2 s . co m*/ if (m.start() != 0) parseError(); offs += m.end(); }
From source file:com.qcadoo.model.internal.ExpressionServiceImpl.java
private String translate(final String expression, final Locale locale) { if (locale == null) { return expression; }//from w w w . j a v a 2 s.c o m Matcher m = Pattern.compile("\\@([a-zA-Z0-9\\.]+)").matcher(expression); StringBuffer sb = new StringBuffer(); int i = 0; while (m.find()) { sb.append(expression.substring(i, m.start())); sb.append(translationService.translate(m.group(1), locale)); i = m.end(); } if (i == 0) { return expression; } sb.append(expression.substring(i, expression.length())); return sb.toString(); }