Example usage for java.util.regex MatchResult group

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

Introduction

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

Prototype

public String group(int group);

Source Link

Document

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

Usage

From source file:org.apache.hadoop.hive.ql.udf.UDFRegExpExtract.java

public String evaluate(String s, String regex, Integer extractIndex) {
    if (s == null || regex == null) {
        return null;
    }//from   w  w w  .  ja v  a2s .  c  om
    if (!regex.equals(lastRegex) || p == null) {
        lastRegex = regex;
        p = Pattern.compile(regex);
    }
    Matcher m = p.matcher(s);
    if (m.find()) {
        MatchResult mr = m.toMatchResult();
        return mr.group(extractIndex);
    }
    return "";
}

From source file:org.kitodo.production.helper.VariableReplacer.java

/**
 * Replace metadata, usage: $(meta.firstchild.METADATANAME).
 *
 * @param input/*from  ww w. j  av a2s  .  c o m*/
 *            String for replacement
 * @return replaced String
 */
private String replaceMetadata(String input) {
    for (MatchResult r : findRegexMatches(NAMESPACE_META, input)) {
        if (r.group(1).toLowerCase().startsWith("firstchild.")) {
            input = input.replace(r.group(),
                    getMetadataFromDigitalDocument(MetadataLevel.FIRSTCHILD, r.group(1).substring(11)));
        } else if (r.group(1).toLowerCase().startsWith("topstruct.")) {
            input = input.replace(r.group(),
                    getMetadataFromDigitalDocument(MetadataLevel.TOPSTRUCT, r.group(1).substring(10)));
        } else {
            input = input.replace(r.group(), getMetadataFromDigitalDocument(MetadataLevel.ALL, r.group(1)));
        }
    }

    return input;
}

From source file:org.kitodo.production.helper.VariableReplacer.java

/**
 * Replace WerkstueckEigenschaft, usage: (product.PROPERTYTITLE).
 *
 * @param input//ww w .  j  a va2s .  c o  m
 *            String for replacement
 * @return replaced String
 */
private String replaceForWorkpieceProperty(String input) {
    for (MatchResult r : findRegexMatches("\\(product\\.([\\w.-]*)\\)", input)) {
        String propertyTitle = r.group(1);
        for (Property workpieceProperty : this.process.getWorkpieces()) {
            if (workpieceProperty.getTitle().equalsIgnoreCase(propertyTitle)) {
                input = input.replace(r.group(), workpieceProperty.getValue());
                break;
            }
        }
    }
    return input;
}

From source file:org.kitodo.production.helper.VariableReplacer.java

/**
 * Replace Vorlageeigenschaft, usage: (template.PROPERTYTITLE).
 *
 * @param input//w ww.j av  a2  s .  co m
 *            String for replacement
 * @return replaced String
 */
private String replaceForTemplateProperty(String input) {
    for (MatchResult r : findRegexMatches("\\(template\\.([\\w.-]*)\\)", input)) {
        String propertyTitle = r.group(1);
        for (Property templateProperty : this.process.getTemplates()) {
            if (templateProperty.getTitle().equalsIgnoreCase(propertyTitle)) {
                input = input.replace(r.group(), templateProperty.getValue());
                break;
            }
        }
    }
    return input;
}

From source file:org.kitodo.production.helper.VariableReplacer.java

/**
 * Replace Prozesseigenschaft, usage: (process.PROPERTYTITLE).
 *
 * @param input//w  w w .ja v  a  2s .  com
 *            String for replacement
 * @return replaced String
 */
private String replaceForProcessProperty(String input) {
    for (MatchResult r : findRegexMatches("\\(process\\.([\\w.-]*)\\)", input)) {
        String propertyTitle = r.group(1);
        List<Property> ppList = this.process.getProperties();
        for (Property pe : ppList) {
            if (pe.getTitle().equalsIgnoreCase(propertyTitle)) {
                input = input.replace(r.group(), pe.getValue());
                break;
            }
        }
    }
    return input;
}

From source file:org.mule.modules.quickbooks.online.api.QuickBooksOnlinePaginatedIterable.java

/**
 * Performs the count query to QuickBooks to calculate the total number of results (all pages) for the original paginated query.
 * /*www. java 2s  .  c  o m*/
 * @return number of total results
 */
public Integer getTotalResultsCount() {
    String cQuery = query.trim();

    Matcher queryMatcher = QuickBooksOnlineQueryEvaluator.matchSelectFieldsPattern(cQuery);

    Validate.isTrue(queryMatcher.matches(), "The query - " + cQuery + " - received is not valid.");

    MatchResult queryMatchResult = queryMatcher.toMatchResult();
    String countQuery = StringUtils.replaceOnce(cQuery, queryMatchResult.group(1), COUNT_QUERY_SELECT_FIELDS);

    try {
        DataService dataService = dataServiceHelper.createIntuitDataService(credentials);
        QueryResult queryResult = dataService.executeQuery(countQuery);

        return queryResult.getTotalCount();
    } catch (FMSException e) {
        throw new QuickBooksRuntimeException(dataServiceHelper.adaptFMSExceptionToExceptionInfo(e), e);
    }
}

From source file:org.nanocom.console.formatter.OutputFormatter.java

/**
 * Replaces style of the output.// ww w  . j  a v a  2  s.c om
 *
 * @param match
 *
 * @return The replaced style
 */
private String replaceStyle(MatchResult matchResult) {
    String match0 = defaultString(matchResult.group(0));
    String match1 = defaultString(matchResult.group(1));
    String match2 = defaultString(matchResult.group(2));
    String match3 = defaultString(matchResult.group(3));

    if (EMPTY.equals(match2)) {
        if ("/".equals(match1)) {
            // Closing tag ("</>")
            styleStack.pop();

            return applyStyle(styleStack.getCurrent(), match3);
        }

        // Opening tag ("<>")
        return "<>" + match3;
    }

    OutputFormatterStyleInterface locStyle;

    if (null != styles.get(match2.toLowerCase())) {
        locStyle = styles.get(match2.toLowerCase());
    } else {
        locStyle = createStyleFromString(match2);

        if (null == locStyle) {
            return match0;
        }
    }

    if ("/".equals(match1)) {
        styleStack.pop(locStyle);
    } else {
        styleStack.push(locStyle);
    }

    return applyStyle(styleStack.getCurrent(), match3);
}

From source file:org.nanocom.console.formatter.OutputFormatter.java

/**
 * Tries to create new style instance from string.
 *
 * @param string/*w  ww.  ja v  a  2 s  . c o  m*/
 *
 * @return Null if string is not format string
 */
private OutputFormatterStyle createStyleFromString(String string) {
    Matcher matcher = STYLE_PATTERN.matcher(string.toLowerCase());

    OutputFormatterStyle style = new OutputFormatterStyle();
    MatchResult result;

    if (!matcher.find()) {
        return null;
    }

    do {
        result = matcher.toMatchResult();
        String match1 = result.group(1); // fg
        String match2 = result.group(2); // blue

        if ("fg".equals(result.group(1))) {
            style.setForeground(result.group(2));
        } else if ("bg".equals(result.group(1))) {
            style.setBackground(result.group(2));
        } else {
            style.setOption(result.group(2));
        }
    } while (matcher.find());

    return style;
}

From source file:org.omegat.gui.scripting.ScriptItem.java

private void scanFileForDescription(File file) {
    try (Scanner scan = new Scanner(file)) {
        scan.findInLine(":name\\s*=\\s*(.*)\\s+:description\\s*=\\s*(.*)");
        MatchResult results = scan.match();
        m_scriptName = results.group(1).trim();
        m_description = results.group(2).trim();
    } catch (IllegalStateException e) {
        /* bad luck */
    } catch (FileNotFoundException e) {
        /* ignore - it should not happen here */
    }/*from www.  j  a  va2s. c om*/
}

From source file:org.wikimedia.analytics.kraken.funnel.UserActionNode.java

/**
 * Split project variable from EventLogging data in language and project
 * component./*from  www  .  ja v a2  s  . c o  m*/
 *
 * @param project the new project
 */
private HashMap<ComponentType, String> splitProject(final String project) {
    MatchResult match = this.wikis.matcher(project);
    HashMap<ComponentType, String> ret = new HashMap<ComponentType, String>();
    ret.put(ComponentType.PROJECT, match.group(0));
    ret.put(ComponentType.LANGUAGE, match.group(1));
    return ret;
}