List of usage examples for java.util.regex Matcher group
public String group()
From source file:Main.java
public static SpannableString replaceImageSpan(CharSequence charSequence, String regPattern, Drawable drawable) {/*from ww w. j ava 2 s. co m*/ SpannableString ss = charSequence instanceof SpannableString ? (SpannableString) charSequence : new SpannableString(charSequence); try { ImageSpan is = new ImageSpan(drawable); Pattern pattern = Pattern.compile(regPattern); Matcher matcher = pattern.matcher(ss); while (matcher.find()) { String key = matcher.group(); ss.setSpan(is, matcher.start(), matcher.start() + key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } catch (Exception ex) { // Logger.e(TAG, ex); } return ss; }
From source file:Main.java
private static String makeUrlHerf(String content) { if (content.trim().length() == 0) { return content; }/*from www . ja va 2 s .c o m*/ StringBuffer urlStringBuffer = new StringBuffer(); Matcher matcherUrl = patternURL.matcher(content); while (matcherUrl.find()) { String url = matcherUrl.group(); // System.out.println("URL:" + url); String urlToHref = "<a href=\"" + url + "\">" + url + "</a>"; matcherUrl.appendReplacement(urlStringBuffer, urlToHref); } matcherUrl.appendTail(urlStringBuffer); return urlStringBuffer.toString(); }
From source file:Main.java
public static String getFileName(String fileName) { Pattern p_ext = Pattern.compile(pattern); Matcher m_ext = p_ext.matcher(fileName); if (m_ext.find()) { return fileName.substring(0, fileName.indexOf(m_ext.group())); } else {//from w ww . j a va 2s . c o m return fileName; } }
From source file:Main.java
/** * Apply a regex on a String/*from w ww .jav a 2 s. c om*/ * * @param stringToParse * @param regex * @return The result of the regex * @throws Exception */ public static String applyRegex(String stringToParse, String regex) throws Exception { // String issue = execute(issueRestUrl); /** * Qui fonctionnent : - (?<=<[\\/?]?)\\w+(?::\\w+)? : retourne le tag - classname=\"(.*?)\" : retourne l'attribut et se valeur */ // System.out.println("Tested string : " + stringToParse); // String regex = "classname=\"(.*?)\""; // .*\"status\":\\{.*?\"name\":\"(.*?)\".*?\\}.* // .?[a-z]*\" Pattern p = Pattern.compile(regex); Matcher m = p.matcher(stringToParse); if (m.find()) { return m.group(); } else { return ""; } }
From source file:Main.java
public static String getDynamicPassword(String str) { Pattern continuousNumberPattern = Pattern.compile("[0-9\\.]+"); Matcher m = continuousNumberPattern.matcher(str); String dynamicPassword = ""; while (m.find()) { if (m.group().length() == 4) { dynamicPassword = m.group(); }/*w w w .j a va2s . c o m*/ } return dynamicPassword; }
From source file:Main.java
public static CharSequence replace(Context ctx, String text) { SpannableString spannableString = new SpannableString(text); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String factText = matcher.group(); String key = factText.substring(1); if (emotionTexts.contains(factText)) { Bitmap bitmap = getDrawableByName(ctx, key); ImageSpan image = new ImageSpan(ctx, bitmap); int start = matcher.start(); int end = matcher.end(); spannableString.setSpan(image, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }/*from w w w . java 2 s . c o m*/ } return spannableString; }
From source file:MatchDuplicateWords.java
public static boolean hasDuplicate(String phrase) { boolean retval = false; String duplicatePattern = "\\b(\\w+) \\1\\b"; Pattern p = null;//from ww w . ja v a 2s .c o m try { p = Pattern.compile(duplicatePattern); } catch (PatternSyntaxException pex) { pex.printStackTrace(); System.exit(0); } int matches = 0; Matcher m = p.matcher(phrase); String val = null; while (m.find()) { retval = true; val = ":" + m.group() + ":"; System.out.println(val); matches++; } String msg = " NO MATCH: pattern:" + phrase + "\r\n regex: " + duplicatePattern; if (retval) { msg = " MATCH : pattern:" + phrase + "\r\n regex: " + duplicatePattern; } System.out.println(msg + "\r\n"); return retval; }
From source file:Main.java
public static CharSequence replace(Context ctx, String text) { if (text == null) { return null; }/*w ww . j av a 2 s . com*/ SpannableString spannableString = new SpannableString(text); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String factText = matcher.group(); String key = factText.substring(1); if (emotionTexts.contains(factText)) { Bitmap bitmap = getDrawableByName(ctx, key); ImageSpan image = new ImageSpan(ctx, bitmap); int start = matcher.start(); int end = matcher.end(); spannableString.setSpan(image, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } return spannableString; }
From source file:Main.java
public static SpannableString replaceImageSpan(CharSequence charSequence, String regPattern, Drawable drawable) {/*from w ww . ja v a 2 s . c o m*/ SpannableString ss = charSequence instanceof SpannableString ? (SpannableString) charSequence : new SpannableString(charSequence); try { ImageSpan is = new ImageSpan(drawable); Pattern pattern = Pattern.compile(regPattern); Matcher matcher = pattern.matcher(ss); while (matcher.find()) { String key = matcher.group(); ss.setSpan(is, matcher.start(), matcher.start() + key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } catch (Exception ex) { ex.printStackTrace(); } return ss; }
From source file:Main.java
public static String format(String input, String... replacements) { String regex = ":[a-zA-Z]*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); Integer i = 0;//from w ww . j a va 2 s .co m while (matcher.find()) { input = input.replace(matcher.group(), replacements[i]); i++; } System.out.println(input); return input; }