List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:Main.java
public static final String getNameFromSelfLink(String selfLink) { Pattern p = Pattern.compile("([^/]+$)"); Matcher m = p.matcher(selfLink); String name = null;/*from w w w .j a v a 2s . c o m*/ if (m.find()) { name = m.group(1); } return name; }
From source file:Main.java
public static List<String> getImageUrls(String content) { List<String> result = new ArrayList<String>(); Pattern pattern = Pattern.compile(REGEX_MATCH_IMAGE, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(1); if (group != null) { result.add(group);/*from w w w. j a v a2 s . c o m*/ } } return result; }
From source file:Main.java
public static String getHrefInnerHtml(String href) { if (isEmpty(href)) { return ""; }//from www .j av a2 s.c o m String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*"; Pattern hrefPattern = Pattern.compile(hrefReg, Pattern.CASE_INSENSITIVE); Matcher hrefMatcher = hrefPattern.matcher(href); if (hrefMatcher.matches()) { return hrefMatcher.group(1); } return href; }
From source file:Main.java
public static String getWithinTags(String matchString, String tag) { final Pattern pattern = Pattern.compile("<" + tag + ">(.+?)</" + tag + ">"); final Matcher matcher = pattern.matcher(matchString); try {//from w w w. ja va 2 s . com matcher.find(); return matcher.group(1); } catch (Exception e) { System.out.println("An exception has occured within tags: " + e.toString()); return ""; } }
From source file:Main.java
public static boolean parseOptionalBooleanAttr(String line, Pattern pattern) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { return BOOLEAN_YES.equals(matcher.group(1)); }//w w w. j av a 2 s . co m return false; }
From source file:Main.java
public static Long parseLong(String value) { if (value == null) { return 0L; }// w ww .j av a 2 s. c om Long val = 0L; try { Matcher matcher = pattern.matcher(value); if (matcher.find()) { String num = matcher.group(0); val = Long.parseLong(num); } } catch (Exception e) { e.printStackTrace(); } return val; }
From source file:Main.java
public static Integer parseInt(String value) { if (value == null) { return 0; }//w w w . j a v a2s. c o m Integer val = 0; try { Matcher matcher = pattern.matcher(value); if (matcher.find()) { String num = matcher.group(0); val = Integer.parseInt(num); } } catch (Exception e) { e.printStackTrace(); } return val; }
From source file:Main.java
public static int parseInt(String s) { Matcher m = sIntMatcher.reset(s); if (!m.find()) return Integer.MIN_VALUE; return Integer.parseInt(m.group(0)); }
From source file:com.android.dialer.lookup.LookupUtils.java
public static String firstRegexResult(String input, String regex, boolean dotall) { if (input == null) { return null; }// w ww . ja v a 2 s . co m Pattern pattern = Pattern.compile(regex, dotall ? Pattern.DOTALL : 0); Matcher m = pattern.matcher(input); return m.find() ? m.group(1).trim() : null; }
From source file:Main.java
public static String getModel(String useragent) { Pattern pattern = Pattern.compile(";\\s?(\\S*?\\s?\\S*?)\\s?(Build)?/"); Matcher matcher = pattern.matcher(useragent); String model = null;// w w w . j a v a2 s . c o m if (matcher.find()) { model = matcher.group(1).trim(); } return model; }