Example usage for java.util.regex Matcher group

List of usage examples for java.util.regex Matcher group

Introduction

In this page you can find the example usage for java.util.regex Matcher group.

Prototype

public String group(String name) 

Source Link

Document

Returns the input subsequence captured by the given named-capturing group during the previous match operation.

Usage

From source file:Main.java

private static String getAaptResult(String sdkPath, String apkPath, final Pattern pattern) {
    try {// w  ww  .  ja v a  2 s .  co  m
        final File apkFile = new File(apkPath);
        final ByteArrayOutputStream aaptOutput = new ByteArrayOutputStream();
        final String command = getAaptDumpBadgingCommand(sdkPath, apkFile.getName());

        Process process = Runtime.getRuntime().exec(command, null, apkFile.getParentFile());

        InputStream inputStream = process.getInputStream();
        for (int last = inputStream.read(); last != -1; last = inputStream.read()) {
            aaptOutput.write(last);
        }

        String packageId = "";
        final String aaptResult = aaptOutput.toString();
        if (aaptResult.length() > 0) {
            final Matcher matcher = pattern.matcher(aaptResult);
            if (matcher.find()) {
                packageId = matcher.group(1);
            }
        }
        return packageId;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String extract(String response, Pattern p) {
    Matcher matcher = p.matcher(response);
    if (matcher.find() && matcher.groupCount() >= 1) {
        try {/*from   w  ww. ja  v  a2  s .  c om*/
            return URLDecoder.decode(matcher.group(1), UTF_8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    throw new RuntimeException(
            "Response body is incorrect. Can't extract token and secret from this: '" + response + "'", null);

}

From source file:Main.java

public static String getProjectByUrl(String url) {
    Pattern pattern = Pattern.compile("https://(\\p{Ll}+).(.*)", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(url);
    if (!matcher.matches())
        throw new IllegalArgumentException("Regex fail. not matched. Url: " + url);

    return matcher.group(1);
}

From source file:com.assemblade.opendj.acis.CompositeSubject.java

public static Subject parse(Subject left, String text) {
    Matcher compositeMatcher = compositePattern.matcher(text);
    if (compositeMatcher.find()) {
        String operand = compositeMatcher.group(1).trim();
        String right = compositeMatcher.group(2);
        if (StringUtils.isNotEmpty(operand)
                && (operand.equalsIgnoreCase("AND") || operand.equalsIgnoreCase("OR"))) {
            return new CompositeSubject(left, Subject.parse(right), operand);
        }//from   w  w  w .j  a v  a  2 s .c  om
    }
    return null;
}

From source file:com.sap.prd.mobile.ios.mios.XCodeVersionUtil.java

public static String getBuildVersion(String xCodeVersionString) throws XCodeException {
    Pattern buildPattern = Pattern.compile("Build version (\\w+)", Pattern.CASE_INSENSITIVE);
    Matcher buildMatcher = buildPattern.matcher(xCodeVersionString);
    if (buildMatcher.find()) {
        return buildMatcher.group(1);
    }//from   w w  w  . j  ava2s .c  o  m
    throw new XCodeException("Could not get xcodebuild build version");
}

From source file:Main.java

public static String getYoutubeVideoId(String url) {
    Pattern pattern = Pattern.compile("^https?://.*(?:youtu.be/|v/|u/\\w/|embed/|watch?v=)([^#&?]*).*$",
            Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(url);
    if (!matcher.matches())
        throw new IllegalArgumentException("Regex fail. not matched. Url: " + url);

    return matcher.group(1);
}

From source file:Main.java

public static CharSequence[] splitLatLon(CharSequence string) {
    Matcher matcherDecimal = PAT_LATLONDEC.matcher(string);
    if (matcherDecimal.matches()) {
        return new String[] { matcherDecimal.group(1).trim(), matcherDecimal.group(2).trim() };
    }//w w w  .j a  v  a2  s  .c  om
    Matcher matcher = PAT_LATLON.matcher(string);
    matcher.matches();
    return new String[] { matcher.group(1).trim(), matcher.group(2).trim() };
}

From source file:hudson.plugins.sonar.utils.SonarUtils.java

/**
 * Read logs of the build to find URL of the project dashboard in Sonar
 *//* ww  w.  j av a 2 s  .com*/
public static String extractSonarProjectURLFromLogs(AbstractBuild<?, ?> build) throws IOException {
    BufferedReader br = null;
    String url = null;
    try {
        br = new BufferedReader(build.getLogReader());
        String strLine;
        while ((strLine = br.readLine()) != null) {
            Pattern p = Pattern.compile(URL_PATTERN_IN_LOGS);
            Matcher match = p.matcher(strLine);
            if (match.matches()) {
                url = match.group(1);
            }
        }
    } finally {
        IOUtils.closeQuietly(br);
    }
    return url;
}

From source file:Main.java

public static CharSequence[] splitCoordsAndDescription(CharSequence location) {
    Matcher matcher = PAT_ATSIGN_FORMAT.matcher(location);
    if (matcher.matches()) {
        return new CharSequence[] { matcher.group(2).trim(), matcher.group(1).trim() };
    }//from  w ww. ja  va  2 s.c o m
    matcher = PAT_PAREN_FORMAT.matcher(location);
    if (matcher.matches()) {
        return new CharSequence[] { matcher.group(1).trim(), matcher.group(2).trim() };
    }
    // No description.
    return new CharSequence[] { location, "" };
}

From source file:com.thoughtworks.go.util.StringUtil.java

public static String matchPattern(String regEx, String s) {
    Pattern pattern = Pattern.compile(regEx);
    Matcher matcher = pattern.matcher(s);
    if (matcher.find()) {
        return matcher.group(1);
    }/* w w w.java  2 s . co m*/
    return null;
}