List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:Main.java
public static String regexText(String source, String regex, int group) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(source); boolean b = matcher.find(); if (b) {//from w w w.j a v a 2 s. co m return matcher.group(group); } return null; }
From source file:Main.java
public static String parseOptionalStringAttr(String line, Pattern pattern) { Matcher matcher = pattern.matcher(line); if (matcher.find() && matcher.groupCount() == 1) { return matcher.group(1); }/*from w ww. j a v a 2s . com*/ return null; }
From source file:Main.java
public static String uuidToString(UUID uuid) { String longUUID = uuid.toString(); Pattern pattern = Pattern.compile("0000(.{4})-0000-1000-8000-00805f9b34fb", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(longUUID); if (matcher.matches()) { // 16 bit UUID return matcher.group(1); } else {//from www.java2 s . c o m return longUUID; } }
From source file:Main.java
public static String getYoutubeVideoId(String youtubeUrl) { String video_id = ""; if (youtubeUrl != null && youtubeUrl.trim().length() > 0 && youtubeUrl.startsWith("http")) { String expression = "^.*((youtu.be" + "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; // var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; CharSequence input = youtubeUrl; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); if (matcher.matches()) { String groupIndex1 = matcher.group(7); if (groupIndex1 != null && groupIndex1.length() == 11) video_id = groupIndex1;/*from w ww . ja v a2s.c o m*/ } } return video_id; }
From source file:cn.wanghaomiao.seimi.utils.StrFormatUtil.java
public static String parseCharset(String target) { Matcher matcher = charsetPattern.matcher(target); if (matcher.find()) { return matcher.group(1); }/* www. java 2 s . co m*/ return ""; }
From source file:Main.java
/** * Remove version information from given objid. * * @param objid The objid.// www . j a va 2s . c om * @return The objid without version information. */ public static String getObjidWithoutVersion(final String objid) { String result = objid; final Matcher m = PATTERN_ID_WITHOUT_VERSION.matcher(objid); if (m.find()) { result = m.group(1); } return result; }
From source file:Main.java
public static <T extends Collection<String>> T findAll(String regex, String content, int group, T collection) { Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { collection.add(matcher.group(group)); }/*ww w .ja va2 s. c o m*/ return collection; }
From source file:Main.java
public static CharSequence[] parseDescription(CharSequence string) { Matcher matcher = PAT_ATLASQUEST.matcher(string); if (matcher.matches()) return new CharSequence[] { "LB" + matcher.group(2).trim(), matcher.group(1).trim() }; return new CharSequence[] { string, "" }; }
From source file:Main.java
/** * Returns local name of the root element of the XML document represented * by the given string, or <code>null</code>, when the given string does * not contain valid XML.// www . ja v a 2s .c om * @param s * XML string. * @return * root element local name, or <code>null</code> when it could not be determined. */ public static String rootElementName(String s) { if (s == null) { return null; } Matcher matcher = ROOT_ELEMENT_PATTERN.matcher(s); return (matcher.find() && (matcher.start() == 0)) ? matcher.group(1) : null; }
From source file:Main.java
/** * Swap the size of a sized image url, returning the new url. * // ww w .j a va 2 s . c o m * Sized image urls encode the image (jpg, jpeg or png) with the image size at the suffix of the url. * * For example: http://www.example.com/image_50.jpg With replacement 100 would return: http://www.example.com/image_100.jpg * * @param url The sized image url. * @param size The new size of the image */ public static String swapSizedImageUrlSize(String url, int size) { if (url == null) throw new IllegalArgumentException("url cannot be null"); Matcher matcher = SIZED_IMAGE_URL_PATTERN.matcher(url); if (!matcher.matches()) return url; return matcher.group(1) + size + "." + matcher.group(2); }