List of usage examples for java.util.regex Matcher end
public int end()
From source file:com.reprezen.kaizen.oasparser.jsonoverlay.gen.Template.java
public static <T> String t(String template, T item, String... args) { Matcher matcher = varPat.matcher(template); StringBuffer result = new StringBuffer(); int start = 0; while (matcher.find()) { // would use matcher.appendReplace and matcher.appendTail, but it's way too hard to deal with all the // escaping and quoting. Literal replacement is what I need here. Too bad they don't support that! result.append(template.substring(start, matcher.start())); result.append(replacement(matcher.group(1), item, args)); start = matcher.end(); }/*from w w w .j a va2s .co m*/ result.append(template.substring(start)); return result.toString(); }
From source file:com.fsck.k9.helper.Utility.java
public static String extractMessageId(final String text) { Matcher matcher = MESSAGE_ID.matcher(text); if (matcher.find()) { return text.substring(matcher.start(), matcher.end()); }/* w w w . j a v a2 s .c o m*/ return null; }
From source file:Grep.java
/** * Use the linePattern to break the given CharBuffer into lines, applying the * input pattern to each line to see if we have a match *///w ww . j a va 2s .c om private static List grep() { List matches = new ArrayList(); Matcher lm = linePattern.matcher(indexFile); // Line matcher Matcher pm = null; // Pattern matcher int lines = 0; while (lm.find()) { lines++; CharSequence cs = lm.group(); // The current line if (pm == null) pm = pattern.matcher(cs); else pm.reset(cs); if (pm.find()) { matches.add(cs.toString()); } if (lm.end() == indexFile.limit()) break; } return matches; }
From source file:org.yamj.core.service.mediaimport.FilenameScanner.java
private static String cutMatch(String rest, Matcher matcher, String divider) { return rest.substring(0, matcher.start()) + divider + rest.substring(matcher.end()); }
From source file:com.github.gekoh.yagen.hibernate.PatchHibernateMappingClasses.java
public static boolean isEmptyStatement(String sqlStmt) { Matcher matcher = COMMENT_PATTERN.matcher(sqlStmt); while (matcher.find()) { sqlStmt = sqlStmt.substring(0, matcher.start()) + sqlStmt.substring(matcher.end()); matcher = COMMENT_PATTERN.matcher(sqlStmt); }/*from w ww . j av a 2 s . c o m*/ return sqlStmt.trim().length() < 1; }
From source file:com.android.dialer.lookup.whitepages.WhitePagesApi.java
private static ContactInfo[] parseOutputUnitedStates(String output, int maxResults) throws IOException { ArrayList<ContactInfo> people = new ArrayList<ContactInfo>(); Pattern regex = Pattern.compile("<li\\s[^>]+?http:\\/\\/schema\\.org\\/Person", Pattern.DOTALL); Matcher m = regex.matcher(output); while (m.find()) { if (people.size() == maxResults) { break; }/*from w w w.j av a2 s. co m*/ // Find section of HTML with contact information String section = extractXmlTag(output, m.start(), m.end(), "li"); // Skip entries with no phone number if (section.contains("has-no-phone-icon")) { continue; } String name = LookupUtils.fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"name\">", "span")); if (name == null) { continue; } // Address String addrCountry = LookupUtils .fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"addressCountry\">", "span")); String addrState = LookupUtils .fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"addressRegion\">", "span")); String addrCity = LookupUtils .fromHtml(extractXmlRegex(section, "<span[^>]+?itemprop=\"addressLocality\">", "span")); StringBuilder sb = new StringBuilder(); if (addrCity != null) { sb.append(addrCity); } if (addrState != null) { if (sb.length() > 0) { sb.append(", "); } sb.append(addrState); } if (addrCountry != null) { if (sb.length() > 0) { sb.append(", "); } sb.append(addrCountry); } // Website Pattern p = Pattern.compile("href=\"(.+?)\""); Matcher m2 = p.matcher(section); String website = null; if (m2.find()) { website = "http://www.whitepages.com" + m2.group(1); } // Phone number is on profile page, so skip if we can't get the // website if (website == null) { continue; } String profile = httpGet(website); String phoneNumber = LookupUtils .fromHtml(extractXmlRegex(profile, "<li[^>]+?class=\"no-overflow tel\">", "li")); String address = parseAddressUnitedStates(profile); if (phoneNumber == null) { Log.e(TAG, "Phone number is null. Either cookie is bad or regex is broken"); continue; } ContactInfo info = new ContactInfo(); info.name = name; info.city = sb.toString(); info.address = address; info.formattedNumber = phoneNumber; info.website = website; people.add(info); } return people.toArray(new ContactInfo[people.size()]); }
From source file:com.fsck.k9.helper.Utility.java
public static List<String> extractMessageIds(final String text) { List<String> messageIds = new ArrayList<String>(); Matcher matcher = MESSAGE_ID.matcher(text); int start = 0; while (matcher.find(start)) { String messageId = text.substring(matcher.start(), matcher.end()); messageIds.add(messageId);//from www .j av a 2 s.co m start = matcher.end(); } return messageIds; }
From source file:Main.java
public static String decodeUnicode(String str) { Charset set = Charset.forName("UTF-16"); Pattern p = Pattern.compile("\\\\u([0-9a-fA-F]{4})"); Matcher m = p.matcher(str); int start = 0; int start2;//from w w w . ja v a 2 s . co m StringBuffer sb = new StringBuffer(); while (m.find(start)) { start2 = m.start(); if (start2 > start) { String seg = str.substring(start, start2); sb.append(seg); } String code = m.group(1); int i = Integer.valueOf(code, 16); byte[] bb = new byte[4]; bb[0] = (byte) ((i >> 8) & 0xFF); bb[1] = (byte) (i & 0xFF); ByteBuffer b = ByteBuffer.wrap(bb); sb.append(String.valueOf(set.decode(b)).trim()); start = m.end(); } start2 = str.length(); if (start2 > start) { String seg = str.substring(start, start2); sb.append(seg); } return sb.toString(); }
From source file:Main.java
public static String unescapeStringForXML(String s) { StringBuilder result = new StringBuilder(); Matcher m = xmlEscapingPattern.matcher(s); int end = 0;//from w w w .j a v a 2 s . com while (m.find()) { int start = m.start(); result.append(s.substring(end, start)); end = m.end(); result.append(translate(s.substring(start, end))); } result.append(s.substring(end, s.length())); return result.toString(); }
From source file:net.krautchan.data.KCPosting.java
public static String sanitizeContent(String inContent) { String locContent = inContent; locContent = StringEscapeUtils.unescapeHtml4(locContent); locContent = locContent.replaceAll("<p>", ""); locContent = locContent.replaceAll("</p>", " "); locContent = locContent.replaceAll("onclick=\"highlightPost\\(\\'\\d+\\'\\);\"", ""); locContent = locContent.replaceAll(">>>(\\d+)</a>", " onclick='quoteClick(this); return false;' class=\"kclink\">>> $1</a>"); locContent = locContent.replaceAll("<a href=\"/resolve(/.+?)\"\\s*>.+?</a>", "<a href=\"/resolve$1\" class=\"kclink\" onclick=\"Android.openKcLink('$1');return false;\">>> $1</a>"); Matcher m = linkPat.matcher(locContent); StringBuffer buf = new StringBuffer(locContent.length() + 1000); int end = 0;// ww w . j a v a2s .c o m while (m.find()) { int gc = m.groupCount(); if (gc > 0) { buf.append(locContent.substring(end, m.start())); end = m.end(); String host = m.group(1); String name = host; String styleClass = "extlink"; String androidFunction = "openExternalLink"; String url = m.group(1) + "/" + m.group(2); if ((host.contains("youtube")) || (host.contains("youtu.be"))) { styleClass = "ytlink"; name = "YouTube"; androidFunction = "openYouTubeVideo"; } else if (host.contains("krautchan.net")) { styleClass = "kclink"; name = ">>"; host = ""; androidFunction = "openKcLink"; } buf.append("<a href=\"http://" + m.group(1) + "/" + m.group(2) + "\" class=\"" + styleClass + "\" onclick=\"Android." + androidFunction + "('" + url + "');return false;\">" + name + "</a>" + m.group(3)); } } buf.append(locContent.substring(end, locContent.length())); return "<p><span>" + buf.toString().trim() + "</span></p>"; }