List of usage examples for java.util.regex Matcher group
public String group()
From source file:Main.java
/** * toSpannableString//from w w w.j a va 2 s . c o m * @return SpannableString * @throws */ public static SpannableString toSpannableString(Context context, String text) { if (!TextUtils.isEmpty(text)) { SpannableString spannableString = new SpannableString(text); 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(); 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); } return spannableString; } else { return new SpannableString(""); } }
From source file:Main.java
public static CharSequence replace(Context context, String text) { if (TextUtils.isEmpty(text)) { return text; }/* www. j a va 2 s. c o m*/ SpannableString spannableString = new SpannableString(text); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String factText = matcher.group(); String key = factText.substring(1, factText.length() - 1); if (contain(emojiCodes, factText)) { Bitmap bitmap = getEmojiDrawable(context, key); ImageSpan image = new ImageSpan(context, 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 List<String> getUrlFromBaidu(String htmlStr) { String IMGURL_REG = "objURL\":\"(http://).*?((.jpg)|(.jpeg)|(.png)|(.JPEG))"; Matcher matcher = Pattern.compile(IMGURL_REG).matcher(htmlStr); List<String> listImgUrl = new ArrayList<String>(); while (matcher.find()) { listImgUrl.add(matcher.group().replace("objURL\":\"", "")); }/*from ww w . j a v a 2 s. c o m*/ return listImgUrl; }
From source file:Main.java
/** Gets all linearDistributions as lists of String. */ public static List<String> getLinearDistributions(String qiesl) { Matcher m = LINEAR_DISTRIUBTIONS.matcher(qiesl); List<String> result = new ArrayList<String>(); while (m.find()) { result.add(m.group()); }/*from ww w . j av a 2 s . c om*/ return result; }
From source file:Main.java
public static List<String> getImgSrcList2(String htmlStr) { String IMGURL_REG = "objURL\":\"(http://).*?((.jpg)|(.jpeg)|(.png)|(.JPEG))"; Matcher matcher = Pattern.compile(IMGURL_REG).matcher(htmlStr); List<String> listImgUrl = new ArrayList<String>(); while (matcher.find()) { listImgUrl.add(matcher.group().replace("objURL\":\"", "")); }//from w w w.ja v a 2 s.co m return listImgUrl; }
From source file:co.cask.cdap.client.rest.TestUtils.java
public static String getStreamNameFromUri(String uri) { String streamName = StringUtils.EMPTY; if (StringUtils.isNotEmpty(uri)) { Pattern p = Pattern.compile("streams/.*?/"); Matcher m = p.matcher(uri); if (m.find()) { String b = m.group(); streamName = b.substring(b.indexOf("/") + 1, b.length() - 1); }/*from w w w. ja va 2 s . c o m*/ } return streamName; }
From source file:com.castlemock.core.basis.utility.parser.TextParser.java
/** * The parse method is responsible for parsing a provided text and transform the text * with the help of {@link Expression}. {@link Expression} in the texts will be transformed * and replaced with new values. The transformed text will be returned. * @param text The provided text that will be transformed. * @return A transformed text. All expressions will be replaced by new values. * Please note that the same text will be returned if no expressions * were found in the provided text. *///from w w w . j a va 2s . c om public static String parse(final String text) { String output = text; Pattern pattern = Pattern.compile("(?=\\$\\{)(.*?)\\}"); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String match = matcher.group(); ExpressionInput expressionInput = ExpressionInputParser.parse(match); Expression expression = EXPRESSIONS.get(expressionInput.getName()); if (expression == null) { LOGGER.error("Unable to parse the following expression: " + expressionInput.getName()); continue; } String expressionResult = expression.transform(expressionInput); output = StringUtils.replaceOnce(output, match, expressionResult); } return output; }
From source file:Main.java
private static void killprocessNormal(String proc, int killMethod) { try {//w ww . j ava 2 s.co m ArrayList<String> pid_list = new ArrayList<String>(); ProcessBuilder execBuilder = null; execBuilder = new ProcessBuilder("sh", "-c", "ps |grep " + proc); execBuilder.redirectErrorStream(true); Process exec = null; exec = execBuilder.start(); InputStream is = exec.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = ""; while ((line = reader.readLine()) != null) { String regEx = "\\s[0-9][0-9]*\\s"; Pattern pat = Pattern.compile(regEx); Matcher mat = pat.matcher(line); if (mat.find()) { String temp = mat.group(); temp = temp.replaceAll("\\s", ""); pid_list.add(temp); } } for (int i = 0; i < pid_list.size(); i++) { execBuilder = new ProcessBuilder("su", "-c", "kill", "-" + killMethod, pid_list.get(i)); exec = null; exec = execBuilder.start(); execBuilder = new ProcessBuilder("su", "-c", "kill" + " -" + killMethod + " " + pid_list.get(i)); exec = null; exec = execBuilder.start(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Helper method trimming the trimString pattern from the text input parameter * /*from w ww . jav a 2 s .co m*/ * @param trimString * regex pattern * @param text * text to be cleaned * @return the input text with any occurrences of the trimString pattern removed. */ private static String trimStringFromText(String trimString, String text) { if (trimString != EMPTY_STRING) { Pattern trimPattern = Pattern.compile(trimString); Matcher matcher = trimPattern.matcher(text); while (matcher.find()) { // System.out.println(matcher.group()); text = text.replace(matcher.group(), EMPTY_STRING); } } return text; }
From source file:Main.java
public static String getEmbeddedChecksum(CharSequence string) { Matcher matcher = EMBEDDED_CHECKSUM.matcher(string); String embeddedChecksum = null; // get last match while (matcher.find()) { embeddedChecksum = matcher.group(); }/*from ww w . jav a 2 s . com*/ return embeddedChecksum; }