Example usage for java.util.regex Matcher start

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

Introduction

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

Prototype

public int start() 

Source Link

Document

Returns the start index of the previous match.

Usage

From source file:com.ephesoft.gxt.systemconfig.server.SystemConfigServiceImpl.java

/**
 * Finds all the matches inside the string for the given regex pattern and returns the list of matched indexes.
 * //from  w ww .  j a  v  a 2s . c om
 * @param regex {@link String} The regex pattern generated.
 * @param strToBeMatched {@link String} The string which is to be matched.
 * @return {@link List<{@link String}> The list of matched indexes.
 * @throws Exception if any exception or error occur.
 */
@Override
public List<String> findMatchedIndexesList(final String regex, final String strToBeMatched) throws UIException {
    List<String> matchedIndexList = null;
    try {
        if (!StringUtil.isNullOrEmpty(regex) && strToBeMatched != null) {
            matchedIndexList = new ArrayList<String>();
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(strToBeMatched);
            while (matcher.find()) {
                matchedIndexList.add(String.valueOf(matcher.start()));
                matchedIndexList.add(String.valueOf(matcher.end()));
            }
        }
    } catch (final PatternSyntaxException patternSyntaxException) {
        throw new UIException("Invalid Regex Pattern.");
    }
    return matchedIndexList;
}