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 getRootName(String path) {
    if (isTrunkPath(path)) {
        return "trunk";
    }/*  w w w . j a  v  a2s .  c o  m*/
    if (isBranchPath(path)) {
        return getBranchName(path);
    }
    if (isTagPath(path)) {
        return getTagName(path);
    }
    if (path.contains("/trunk/")) {
        return "trunk";
    }

    final Pattern pattern = Pattern.compile(".*/(branches|tags)/([^/]+)(/.*)?");

    final Matcher matcher = pattern.matcher(path);

    if (matcher.matches()) {
        return matcher.group(2);
    }

    return null;
}

From source file:jetbrick.tools.chm.reader.AnchorNameManager.java

public static void addAnchor(File file, String encoding) throws IOException {
    String html = FileUtils.readFileToString(file, encoding);
    html = html.replace('$', '\uFFE5');

    Pattern p = Config.style.getAnchorNameRegex();
    Matcher m = p.matcher(html);

    int findCount = 0;
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        findCount++;/*from w w  w .j  a va  2 s .c o m*/
        String anchor = m.group(1);
        // String oldAnchor = m.group();
        String oldAnchor = "<A HH=\"1\" NAME=\"" + anchor + "\">";
        String newAnchor = "<A HH=\"1\" NAME=\"" + getNewAnchorName(anchor) + "\"></A>";
        m.appendReplacement(sb, newAnchor + oldAnchor);
    }
    m.appendTail(sb);

    System.out.println("addAnchor(" + findCount + ") : " + file);

    if (findCount > 0) {
        html = sb.toString().replace('\uFFE5', '$');
        FileUtils.writeStringToFile(file, html, encoding);
    }
    html = null;
}

From source file:com.jennifer.ui.util.ColorUtil.java

private static Object parsedGradient(String color) {

    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(color);

    if (!m.matches())
        return color;

    String type = m.group(1).trim();
    JSONObject attr = parseAttr(type, m.group(2).trim());
    JSONArray stops = parseStop(m.group(3).trim());

    JSONObject o = new JSONObject();
    o.put("type", type);

    o = JSONUtil.extend(o, attr);//from  w  w  w .  ja  va2  s  .c  om

    o.put("stops", stops);

    return o;
}