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:com.github.fritaly.svngraph.Utils.java

public static String getTagPath(String path) {
    final Pattern pattern = Pattern.compile("(.*/tags/([^/]+))(/.*)?");

    final Matcher matcher = pattern.matcher(path);

    return matcher.matches() ? matcher.group(1) : null;
}

From source file:com.github.fritaly.svngraph.Utils.java

public static String getTrunkPath(String path) {
    final Pattern pattern = Pattern.compile("(.*/trunk)(/.*)?");

    final Matcher matcher = pattern.matcher(path);

    return matcher.matches() ? matcher.group(1) : null;
}

From source file:com.threewks.thundr.http.ContentType.java

/**
 * Removes extraneous information from the content-type header, such as encoding etc.
 * If this is not recognised as a content type, returns the input.
 * // w  w w. j  a va  2 s. c o  m
 * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
 * @param rawContentType
 * @return
 */
public static String cleanContentType(String rawContentType) {
    if (rawContentType != null) {
        Matcher matcher = contentTypePattern.matcher(rawContentType);
        if (matcher.matches()) {
            return (matcher.group(1) + "/" + matcher.group(2)).toLowerCase();
        }
    }
    return rawContentType;
}

From source file:Main.java

public static String searchForPattern(String message, String pattern) {

    Pattern first = Pattern.compile(pattern);
    Matcher match = first.matcher(message);
    //Log.i("parseMessageForMeetingID",Integer.toString(match.groupCount()));

    if (match.find()) {
        String str = match.group(0);
        Log.i("searchForPattern", str);
        return str;
    }//www .  j  a v a  2  s  .co m
    Log.i("searchForPattern", "no match found");
    return null;
}

From source file:com.castlabs.dash.helpers.ManifestHelper.java

private static String replace(Matcher m, String rv, Object value) {
    while (m.find()) {
        if (m.group(2) != null) {
            rv = rv.replace(m.group(0), String.format(m.group(2), value));
        } else {/*from ww w .j  a  v a 2  s. co m*/
            rv = rv.replace(m.group(0), String.valueOf(value));
        }
    }
    return rv;
}

From source file:com.ejisto.core.classloading.util.ReflectionUtils.java

public static String getActualType(String type) {
    String actualType = type;//ww  w  .  j ava  2 s .  c  om
    Matcher m = TYPE_EXTRACTOR.matcher(actualType);
    if (m.matches()) {
        actualType = m.group(1);
    }
    if (primitives.containsKey(actualType)) {
        return primitives.get(actualType);
    }
    return actualType;
}

From source file:com.haulmont.cuba.core.global.filter.ParametersHelper.java

public static Set<String> extractNames(String text) {
    Set<String> set = new HashSet<>();

    Matcher matcher = QUERY_PARAMETERS_PATTERN.matcher(text);
    while (matcher.find()) {
        set.add(matcher.group(2));
    }/*from   w w  w  .java2  s  .co  m*/

    return set;
}

From source file:com.ufukuzun.myth.dialect.util.ExpressionUtils.java

public static String[] splitRenderFragmentAndUpdates(String value) {
    String renderFragment = "";
    String updates = "";

    if (StringUtils.isNotBlank(value)) {
        Matcher matcher = RENDER_EXPRESSION_PATTERN.matcher(value);
        if (matcher.matches()) {
            renderFragment = matcher.group(1).trim();
            updates = matcher.group(2).trim();
        }/* w w  w . j a v a  2s  . c  o  m*/
    }

    return new String[] { renderFragment, updates };
}

From source file:com.github.fritaly.svngraph.Utils.java

public static String getTagName(String path) {
    final Matcher matcher = TAG_PATTERN.matcher(path);

    return matcher.matches() ? matcher.group(1) : null;
}

From source file:fi.ilmoeuro.membertrack.db.DataIntegrityException.java

public static @Nullable DataIntegrityException fromThrowable(Throwable throwable) {
    Throwable rootCause = ExceptionUtils.getRootCause(throwable);

    if (rootCause instanceof SQLException) {
        SQLException sqle = (SQLException) rootCause;
        String constraint = "";
        String message = sqle.getMessage();
        if (message != null) {
            Matcher matcher = CONSTRAINT_REGEX.matcher(message);

            if (matcher.find()) {
                String group = matcher.group(1);
                if (group != null) {
                    constraint = group;/*from  w  ww .j av a2s  . co  m*/
                }
            }
        }

        for (IntegrityViolation errorType : IntegrityViolation.values()) {
            if (errorType.errorCodes.contains(sqle.getSQLState())) {
                return new DataIntegrityException(errorType, constraint, throwable);
            }
        }
    }

    return null;
}