List of usage examples for java.util.regex Matcher end
public int end()
From source file:Correct.java
public static void execute(String One, String Two) { Two = Two.replaceAll("\\\\n", "\n"); try {/*from w ww .j av a 2s . co m*/ System.out.println("Regex = " + One); System.out.println("Input = " + Two); Pattern pattern = Pattern.compile(One); Matcher match = pattern.matcher(Two); while (match.find()) { System.out.println("Found [" + match.group() + "]\nStarting at " + match.start() + " , \nEnding at " + (match.end() - 1)); } } catch (PatternSyntaxException pse) { System.err.println("Bad regex: " + pse.getMessage()); System.err.println("Description: " + pse.getDescription()); System.err.println("Index: " + pse.getIndex()); System.err.println("Incorrect pattern: " + pse.getPattern()); } }
From source file:Main.java
/** * replace existing spannable with smiles * //from w ww . j ava2s . c o m * @param context * @param spannable * @return */ public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; }
From source file:Main.java
/** * replace existing spannable with smiles * @param context//from w ww.j a v a 2 s . c o m * @param spannable * @return */ public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Object> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; Object value = entry.getValue(); if (value instanceof String && !((String) value).startsWith("http")) { File file = new File((String) value); if (!file.exists() || file.isDirectory()) { return false; } spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { spannable.setSpan(new ImageSpan(context, (Integer) value), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } } return hasChanges; }
From source file:net.sourceforge.vulcan.maven.integration.MavenProjectConfiguratorImpl.java
public static String normalizeScmUrl(final String url) { final StringBuilder sb = new StringBuilder(url); if (!url.endsWith("/")) { sb.append('/'); }/*from www . j a va 2s .c o m*/ final Matcher matcher = SCM_URL_PREFIX.matcher(sb); while (matcher.find()) { sb.delete(0, matcher.end()); matcher.reset(); } return sb.toString(); }
From source file:testingproject.TestingProjectDLB.java
static List<String> getData(String pageContent) { List<String> dataList = new ArrayList<String>(); String patternString1 = "<tr class=\"alt\">"; Pattern pattern1 = Pattern.compile(patternString1); Matcher matcher1 = pattern1.matcher(pageContent); if (matcher1.find()) { //System.out.println(matcher1.group()); String filteredStr = pageContent.substring(matcher1.end()).trim(); //System.out.println(filteredStr); String patternString2 = "<td><div align=\"right\">"; Pattern pattern2 = Pattern.compile(patternString2); Matcher matcher2 = pattern2.matcher(filteredStr); while (matcher2.find()) { String filteredStr2 = filteredStr.substring(matcher2.end()).trim(); String data = filteredStr2.split(" ")[0]; //System.out.println(data); dataList.add(data);// ww w . j a v a 2 s . c o m } // System.out.println(filteredStr); String patternString3 = "<img src=\"/dlb/images/stories/signs/"; Pattern pattern3 = Pattern.compile(patternString3); Matcher matcher3 = pattern3.matcher(filteredStr); while (matcher3.find()) { String filteredStr3 = filteredStr.substring(matcher3.end()).trim(); String data = filteredStr3.split(".jpg")[0]; //System.out.println(map.get(data)); dataList.add(map.get(data)); } } return dataList; }
From source file:com.processpuzzle.fundamental_types.domain.ParameterDefinition.java
public static ParameterDefinition parse(String definitionText) throws ClassNotFoundException { Pattern namePattern = Pattern.compile("([a-z]|[A-Z]|[0-9])+\\s*:"); Matcher nameFinder = namePattern.matcher(definitionText); String name = null;/*from w ww. ja v a2 s . com*/ if (nameFinder.find()) { name = StringUtils.strip(nameFinder.group().substring(0, nameFinder.end() - 1)); } Pattern typePattern = Pattern.compile(":\\s*([^]]+)(\\[|=)"); Matcher typeFinder = typePattern.matcher(definitionText); String type = null; if (typeFinder.find()) { type = "java.lang." + StringUtils.strip(typeFinder.group().substring(1, typeFinder.group().length() - 1)); } Pattern multiplicityPattern = Pattern.compile("\\[([^]]+)\\]"); Matcher multiplicityFinder = multiplicityPattern.matcher(definitionText); String multiplicity = null; if (multiplicityFinder.find()) { multiplicity = StringUtils .strip(multiplicityFinder.group().substring(1, multiplicityFinder.group().length() - 1)); } Pattern descriptionPattern = Pattern.compile("//([A-Z]|[a-z]|\\s|\\.)*"); Matcher descriptionFinder = descriptionPattern.matcher(definitionText); String description = null; if (descriptionFinder.find()) { description = StringUtils.strip(descriptionFinder.group().substring(2)); } return new ParameterDefinition(name, type, multiplicity, description); }
From source file:msi.gama.common.util.StringUtils.java
public static List<String> tokenize(final String expression) { if (expression == null) { return Collections.EMPTY_LIST; }//from w w w. j a v a2 s. c om final Pattern p = Pattern.compile(regex); final List<String> tokens = new ArrayList<String>(); final Matcher m = p.matcher(expression); while (m.find()) { tokens.add(expression.substring(m.start(), m.end())); } return tokens; }
From source file:Main.java
/** * Escape some special character as HTML escape sequence. * //from w w w . j a v a2s . c o m * @param text Text to be displayed using WebView. * @return Text correctly escaped. */ public static String escapeCharacterToDisplay(String text) { Pattern pattern = PLAIN_TEXT_TO_ESCAPE; Matcher match = pattern.matcher(text); if (match.find()) { StringBuilder out = new StringBuilder(); int end = 0; do { int start = match.start(); out.append(text.substring(end, start)); end = match.end(); int c = text.codePointAt(start); if (c == ' ') { // Escape successive spaces into series of " ". for (int i = 1, n = end - start; i < n; ++i) { out.append(" "); } out.append(' '); } else if (c == '\r' || c == '\n') { out.append("<br>"); } else if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } } while (match.find()); out.append(text.substring(end)); text = out.toString(); } return text; }
From source file:Main.java
public static String replaceCheatSheetEmojis(String s) { if (TextUtils.isEmpty(s)) { return ""; }/*from w w w. j a v a2 s . c o m*/ Matcher matcher = COLON_REGEX.matcher(s); List<int[]> linkRanges = getLinksRanges(s); List<int[]> potentialMatches = new ArrayList<int[]>(); OUTER: while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); for (int[] range : linkRanges) { if (start <= range[1] && range[0] <= end) { continue OUTER; } } potentialMatches.add(0, new int[] { start, end }); } for (int[] potentialMatch : potentialMatches) { String toReplace = s.substring(potentialMatch[0], potentialMatch[1]); String replacement = CHEAT_SHEET_TO_UNICODE.get(toReplace); if (!TextUtils.isEmpty(replacement)) { String newString = s.substring(0, potentialMatch[0]) + replacement; if (potentialMatch[1] <= s.length()) { newString += s.substring(potentialMatch[1]); } s = newString; } } return s; }
From source file:net.sf.jabref.importer.fetcher.ScienceDirectFetcher.java
private static String getCitationsFromUrl(String urlQuery, List<String> ids) throws IOException { String cont = new URLDownload(urlQuery).downloadToString(Globals.prefs.getDefaultEncoding()); Matcher m = ScienceDirectFetcher.LINK_PATTERN.matcher(cont); if (m.find()) { while (m.find()) { ids.add(ScienceDirectFetcher.LINK_PREFIX + m.group(1)); cont = cont.substring(m.end()); m = ScienceDirectFetcher.LINK_PATTERN.matcher(cont); }/* w ww.j a va 2 s . co m*/ } else { return null; } return null; }