List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:com.offbynull.portmapper.common.RegexUtils.java
/** * Finds all IPv4 addresses in a block of text. * @param text block of text to search in * @return all IPv4 addresses in {@code text} * @throws NullPointerException if any argument is {@code null} */// w ww . j a v a2 s. co m public static List<String> findAllIpv4Addresses(String text) { Validate.notNull(text); List<String> ret = new LinkedList<>(); Matcher matcher = IPV4_PATTERN.matcher(text); while (matcher.find()) { ret.add(matcher.group(0)); } return ret; }
From source file:Main.java
static String parseContentDisposition(String contentDisposition) { try {/* w w w .jav a2 s . co m*/ Matcher m = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition); if (m.find()) { return m.group(1); } } catch (IllegalStateException ex) { // This function is defined as returning null when it can't parse // the header } return null; }
From source file:Main.java
private static String parseContentDisposition(String contentDisposition) { try {//from w ww.ja va 2s . c om Matcher m = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition); if (m.find()) { return m.group(1); } } catch (IllegalStateException ex) { // This function is defined as returning null when it can't parse // the header } return null; }
From source file:Main.java
public static String findAppropriateIp() { String result = "unknown"; Enumeration<NetworkInterface> e; try {/*w w w . j av a2 s . c om*/ e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { return result; } while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress inetAddr = ee.nextElement(); String ipAddr = inetAddr.getHostAddress(); Matcher m = ipAddrPattern.matcher(ipAddr); if (m.matches()) { if (!m.group(1).equals("127")) { result = ipAddr; } } } } return result; }
From source file:Main.java
/** * Get all the matches for {@code string} compiled by {@code pattern}. If * {@code isGlobal} is true, the return results will only include the * group 0 matches. It is similar to string.match(regexp) in JavaScript. * /*from www .j av a2s .c o m*/ * @param pattern the regexp * @param string the string * @param isGlobal similar to JavaScript /g flag * * @return all matches */ public static String[] match(Pattern pattern, String string, boolean isGlobal) { if (pattern == null) { throw new NullPointerException("argument 'pattern' cannot be null"); } if (string == null) { throw new NullPointerException("argument 'string' cannot be null"); } List<String> matchesList = new ArrayList<String>(); Matcher matcher = pattern.matcher(string); while (matcher.find()) { matchesList.add(matcher.group(0)); if (!isGlobal) { for (int i = 1, iEnd = matcher.groupCount(); i <= iEnd; i++) { matchesList.add(matcher.group(i)); } } } return matchesList.toArray(new String[matchesList.size()]); }
From source file:Main.java
public static String getClassNameFromTableName(String tableName) { Pattern p = Pattern.compile("(_+|^)(\\w?)"); Matcher m = p.matcher(tableName); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, m.group(2).toUpperCase()); }/*from w ww. j av a 2 s.co m*/ m.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static List<String> listAvailableIosPlatformVersions() { List<String> results = new ArrayList<String>(); try {//from www. ja v a2 s . c o m ProcessBuilder pb = new ProcessBuilder("xcodebuild", "-showsdks"); pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; Pattern pattern = Pattern.compile("-sdk iphoneos(([0-9]+.?)+)"); while ((line = reader.readLine()) != null) { Matcher m = pattern.matcher(line); while (m.find()) { results.add(m.group(1)); } } } catch (Throwable t) { } return results; }
From source file:Main.java
public static String fixTagEndings(String body) { String newBody = body;//from w ww .j a v a 2 s.c o m Matcher matcher = ENDTAG_AFTER_NEWLINE_PATTERN.matcher(body); while (matcher.find()) { String endTag = matcher.group(1); newBody = newBody.replaceFirst("\n" + endTag, endTag + "\n"); matcher = ENDTAG_AFTER_NEWLINE_PATTERN.matcher(newBody); } return newBody; }
From source file:Main.java
private static String parseContentDisposition(String paramString) { try {// w ww .j a v a 2 s . c o m Matcher localMatcher = CONTENT_DISPOSITION_PATTERN.matcher(paramString); if (localMatcher.find()) { String str = localMatcher.group(1); return str; } } catch (IllegalStateException localIllegalStateException) { } return null; }
From source file:Main.java
public static String changeED2K(String url) { // TODO Auto-generated method stub Pattern pat = Pattern//from ww w . j a v a2 s.c om .compile("ed2k:\\/\\/\\|file\\|([^\\|]+?)\\|(\\d+)\\|([A-Z0-9]{32})\\|(h=[A-Z0-9]{32}\\|)?\\/?"); Matcher mat = pat.matcher(url); // System.out.println(url); if (mat.find()) { String name = "" + mat.group(1); if (name.contains(".")) { String temp = "1" + name.substring(name.lastIndexOf(".")); url = url.replace(name, temp); // System.out.println(url); } } if (url.startsWith("magnet:?xt=urn:btih:") && url.contains("&")) { url = url.substring(0, url.indexOf("&")).toLowerCase(); } return url; }