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:net.rptools.tokentool.util.FileSaveUtil.java

public static String searchURL(String urlString) {
    String imageTypes = "";

    for (String type : ImageUtil.SUPPORTED_FILE_FILTER_ARRAY) {
        if (imageTypes.isEmpty())
            imageTypes = type;/* www  .j a  v  a 2 s.  c  o m*/
        else
            imageTypes += "|" + type;
    }
    Pattern p = Pattern.compile("([\\w-]+)\\.(?i:" + imageTypes.replace(".", "") + ")");
    Matcher m = p.matcher(urlString);

    if (m.find())
        return m.group(1);
    else
        return FilenameUtils.getBaseName(urlString);
}

From source file:tv.icntv.common.HttpClientUtil.java

private static String getPageEncoding(HttpResponse response) {
    Header contentType = response.getEntity().getContentType();
    if (contentType == null || Strings.isNullOrEmpty(contentType.getValue())) {
        return null;
    }//  w  w w.  j a  va  2 s .  c o  m
    Matcher matcher = PATTERN_HTML_CHARSET.matcher(contentType.getValue());
    if (matcher.find()) {
        return matcher.group(1);
    }
    return null;
}

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

public static DefaultArtifactVersion getVersion(String xCodeVersionString) throws XCodeException {
    Pattern versionPattern = Pattern.compile("Xcode (\\d+(\\.\\d+)+)", Pattern.CASE_INSENSITIVE);
    Matcher versionMatcher = versionPattern.matcher(xCodeVersionString);
    if (versionMatcher.find()) {
        return new DefaultArtifactVersion(versionMatcher.group(1));
    }// w w  w.  j a  v  a 2s .c o  m
    throw new XCodeException("Could not get xcodebuild version");
}

From source file:jenkins.scm.impl.subversion.SubversionSampleRepoRule.java

private static String uuid(String url) throws Exception {
    Process proc = new ProcessBuilder("svn", "info", "--xml", url).start();
    BufferedReader r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    Pattern p = Pattern.compile("<uuid>(.+)</uuid>");
    String line;/*  w ww. j av a  2  s.c  o m*/
    while ((line = r.readLine()) != null) {
        Matcher m = p.matcher(line);
        if (m.matches()) {
            return m.group(1);
        }
    }
    throw new IllegalStateException("no output");
}

From source file:mitm.common.util.PhoneNumberUtils.java

/**
 * Checks if the input can be a valid phone number. The phone number must have a country code (country
 * codes are not checked) and must not start with a 0.
 * If input cannot be a valid phone number of input is null null is returned otherwise the phone number
 * is returned (with start and end spaces removed).
 *//*from   ww w  .ja  va  2s  . c  o m*/
public static String filterAndValidatePhoneNumber(String input) {
    if (input == null) {
        return null;
    }

    String phoneNumber = null;

    Matcher matcher = PHONE_NUMBER_PATTERN.matcher(input);

    if (matcher.matches()) {
        phoneNumber = matcher.group(1);

        if (phoneNumber.startsWith("0")) {
            logger.warn("Phone number starts with 0 which is not a valid country code.");

            phoneNumber = null;
        }
    }

    return phoneNumber;
}

From source file:net.shopxx.util.TokenUtil.java

/**
 * ?openid//from   www  .ja  v a 2s  .c o  m
 * 
 * @param @param string
 * @param @return 
 * @return String 
 * @throws
 */
public static String getOpenId(String string) {
    String openid = null;
    Matcher m = Pattern.compile("\"openid\"\\s*:\\s*\"(\\w+)\"").matcher(string);
    if (m.find())
        openid = m.group(1);
    return openid;
}

From source file:springfox.documentation.schema.property.bean.Accessors.java

public static String propertyName(Method method) {
    Optional<JsonGetter> jsonGetterAnnotation = getterAnnotation(method);
    if (jsonGetterAnnotation.isPresent() && !isNullOrEmpty(jsonGetterAnnotation.get().value())) {
        return jsonGetterAnnotation.get().value();
    }/*ww  w.j a va 2s  .  c o m*/
    Optional<JsonSetter> jsonSetterAnnotation = setterAnnotation(method);
    if (jsonSetterAnnotation.isPresent() && !isNullOrEmpty(jsonSetterAnnotation.get().value())) {
        return jsonSetterAnnotation.get().value();
    }
    Matcher matcher = getter.matcher(method.getName());
    if (matcher.find()) {
        return toCamelCase(matcher.group(1));
    }
    matcher = isGetter.matcher(method.getName());
    if (matcher.find()) {
        return toCamelCase(matcher.group(1));
    }
    matcher = setter.matcher(method.getName());
    if (matcher.find()) {
        return toCamelCase(matcher.group(1));
    }
    return "";
}

From source file:io.knotx.adapter.common.placeholders.SlingUriInfoHelper.java

private static SlingUriInfo generateSlingUriInfo(String uri) {
    final Matcher matcher = URI_PATTERN.matcher(uri);
    SlingUriInfo uriInfo = null;//  ww  w  .ja va 2 s  .c  o  m
    if (matcher.matches()) {
        String path = matcher.group(1);
        String[] pathParts = StringUtils.length(path) > 1 ? path.substring(1).split("/")
                : new String[] { path };

        String selectorString = matcher.group(3);
        String[] selectors = selectorString != null ? selectorString.split("\\.") : new String[0];

        String extension = matcher.group(5);
        String suffix = matcher.group(6);

        uriInfo = new SlingUriInfo(path, pathParts, selectorString, selectors, extension, suffix);
    }
    return uriInfo;
}

From source file:Main.java

public static List<String> matcher(String reg, String text) {
    List<String> matches = new ArrayList<String>();
    Matcher m = Pattern.compile(reg).matcher(text);
    if (m.find()) {
        if (m.groupCount() > 0) {
            for (int i = 1; i <= m.groupCount(); i++) {
                matches.add(m.group(i));
            }// w  ww .  j a va 2  s  . c  o  m
        }
    }

    return matches;
}

From source file:com.diyshirt.util.RegexUtil.java

/**
 * obfuscate plaintext emails: makes them
 * "human-readable" - still too easy for
 * machines to parse however./*w  w  w .j  a  v  a2  s.c  om*/
 */
public static String obfuscateEmail(String str) {
    Matcher emailMatch = emailPattern.matcher(str);
    while (emailMatch.find()) {
        String at = emailMatch.group(1);
        //System.out.println("at=" + at);
        str = str.replaceFirst(at, "-AT-");

        String dot = emailMatch.group(2) + emailMatch.group(3) + emailMatch.group(4);
        String newDot = emailMatch.group(2) + "-DOT-" + emailMatch.group(4);
        //System.out.println("dot=" + dot);
        str = str.replaceFirst(dot, newDot);
    }
    return str;
}