List of usage examples for java.util.regex Matcher group
public String group()
From source file:Main.java
private static String makeEmailHerf(String content) { if (content.trim().length() == 0) { return content; }//w w w . j av a2s . c o m StringBuffer emailStringBuffer = new StringBuffer(); Matcher matcherEmail = patternEmail.matcher(content); while (matcherEmail.find()) { String email = matcherEmail.group(); // System.out.println("email:" + email); String emailToHref = "<a href=\"" + MailTo.MAILTO_SCHEME + email + "\">" + email + "</a>"; matcherEmail.appendReplacement(emailStringBuffer, emailToHref); } matcherEmail.appendTail(emailStringBuffer); return emailStringBuffer.toString(); }
From source file:Main.java
private static String makeTelNoHerf(String telContent) { if (telContent.trim().length() == 0) { return telContent; }//from w w w . j av a 2s . c o m StringBuffer telNoStringBuffer = new StringBuffer(); Matcher matcherTelNo = patternTelNo.matcher(telContent); while (matcherTelNo.find()) { String telNo = matcherTelNo.group(); String telNoToHerf = "<a href=\"" + ProtocolKey_ACTION_DIAL + telNo + "\">" + telNo + "</a>"; matcherTelNo.appendReplacement(telNoStringBuffer, telNoToHerf); } matcherTelNo.appendTail(telNoStringBuffer); return telNoStringBuffer.toString(); }
From source file:Main.java
public static String toHref(String title) { StringBuffer sb = new StringBuffer(title); Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(title); int index = 0; int index1 = 0; while (mat.find()) { String url = mat.group(); //System.out.println(url); if (url.indexOf("http://") != 0) url = "http://" + url; Object obj[] = { "'" + url + "'" }; String a = MessageFormat.format(A1, obj); int l = a.length(); index += index1;/*from w ww . j a v a 2s. co m*/ sb.insert(mat.start() + index, a); index += l; sb.insert((mat.end()) + index, A2); index1 = A2.length(); } return sb.toString(); }
From source file:brooklyn.entity.cloudfoundry.LocalResourcesDownloader.java
public static String findArchiveNameFromUrl(String url) { String name = url.substring(url.lastIndexOf('/') + 1); if (name.indexOf("?") > 0) { Pattern p = Pattern.compile("[A-Za-z0-9_\\-]+\\..(ar|AR)($|(?=[^A-Za-z0-9_\\-]))"); Matcher wars = p.matcher(name); if (wars.find()) { name = wars.group(); }/* w w w . ja va 2s . c o m*/ } return name; }
From source file:Main.java
private static String capitalizeTagNames(String xpath) { Matcher m = TAG_PATTERN.matcher(xpath); StringBuffer sb = new StringBuffer(); while (m.find()) { String text = m.group(); m.appendReplacement(sb, Matcher.quoteReplacement(text.toUpperCase())); }//from ww w . j av a2s .com m.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static SpannableString toSpannableString(Context context, String text, SpannableString spannableString) { int start = 0; Pattern pattern = Pattern.compile("\\\\ue[a-z0-9]{3}", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); // options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(key, "drawable", context.getPackageName()), options); ImageSpan imageSpan = new ImageSpan(context, bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1);//from w w w . j a v a2 s . c om } return spannableString; }
From source file:fi.otavanopisto.changelogger.Changelogger.java
private static List<Integer> getIssueNumbers(String description) { List<Integer> issues = new ArrayList<>(); Matcher matcher = ISSUE_REGEX.matcher(description); while (matcher.find()) { issues.add(Integer.parseInt(matcher.group())); }//from w ww . jav a2 s .co m return issues; }
From source file:Main.java
@NonNull public static int[] getStartEnd(@Nullable String s) { if (TextUtils.isEmpty(s)) { return new int[] { -1, -1 }; }//w w w .j a v a 2 s .co m Matcher first = Pattern.compile(timeDuringPattern).matcher(s); if (first.find()) { String sS = first.group(); if (!TextUtils.isEmpty(sS)) { int start = Integer.parseInt(first.group()); Matcher last = Pattern.compile(lastNumberPattern).matcher(s); int end = start; if (last.find()) { String eS = last.group(); if (!TextUtils.isEmpty(eS)) { end = Integer.parseInt(eS); } } return new int[] { start, end }; } else { return new int[] { -1, -1 }; } } else { return new int[] { -1, -1 }; } }
From source file:Main.java
public static String encodeUrl(String url) { String new_url = url; Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(new_url); while (matcher.find()) { try {/* ww w .j a v a 2 s . co m*/ new_url = new_url.replaceAll(matcher.group(), URLEncoder.encode(matcher.group(), "gb2312")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return new_url; }
From source file:Main.java
public static boolean contain(String text) { boolean isContain = false; if (TextUtils.isEmpty(text)) { return false; }/*w w w . j a v a 2s. c o m*/ Matcher matcher = pattern.matcher(text); while (matcher.find()) { String factText = matcher.group(); if (contain(emojiCodes, factText)) { isContain = true; break; } } return isContain; }