com.github.jlgrock.javascriptframework.mavenutils.parsing.ParseUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-utils Show documentation
Show all versions of maven-utils Show documentation
Although this is technically not a plugin, this is a bunch of tools that all of the plugins use. This is very useful for anyone doing maven plugin development.
package com.github.jlgrock.javascriptframework.mavenutils.parsing;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Utilities for parsing strings.
*/
public final class ParseUtils {
/**
* Private constructor.
*/
private ParseUtils() {}
/**
* Parse the test into groups based on the regular expression.
* @param regex the regex to use
* @param parseText the text to parse
* @return an array of strings from the parsing.
*/
public static String[] parseIntoGroups(final String regex, final String parseText) {
ArrayList parsedValues = new ArrayList();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(parseText);
boolean matches = matcher.find();
if (matches) {
// Get all groups for this match
for (int i=0; i<=matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
parsedValues.add(groupStr);
}
}
return parsedValues.toArray(new String[parsedValues.size()]);
}
}