/** * Does the given argument match the pattern? * @param input the string to match against * @param options the regex options to use * @return true if the pattern matches * @throws BuildException on error */ @Override public boolean matches(String input, int options) throws BuildException { return matches(input, getCompiledPattern(options)); }
/** * Returns a Vector of matched groups found in the argument * using default options. * * <p>Group 0 will be the full match, the rest are the * parenthesized subexpressions</p>. * * @param argument the string to match against * @return the vector of groups * @throws BuildException on error */ @Override public Vector<String> getGroups(String argument) throws BuildException { return getGroups(argument, MATCH_DEFAULT); }
/** * Does the given argument match the pattern? * @param argument the string to match against * @return true if the pattern matches * @throws BuildException on error */ @Override public boolean matches(String argument) throws BuildException { return matches(argument, MATCH_DEFAULT); }
/** * Compile the pattern. * * @param options the ant regexp options * @return a compiled pattern * @exception BuildException if an error occurs */ protected RE getCompiledPattern(int options) throws BuildException { int cOptions = getCompilerOptions(options); try { RE reg = new RE(pattern); reg.setMatchFlags(cOptions); return reg; } catch (RESyntaxException e) { throw new BuildException(e); } }
/** * Returns a Vector of matched groups found in the argument. * * <p>Group 0 will be the full match, the rest are the * parenthesized subexpressions</p>. * * @param input the string to match against * @param options the regex options to use * @return the vector of groups * @throws BuildException on error */ @Override public Vector<String> getGroups(String input, int options) throws BuildException { RE reg = getCompiledPattern(options); if (!matches(input, reg)) { return null; } Vector<String> v = new Vector<>(); int cnt = reg.getParenCount(); for (int i = 0; i < cnt; i++) { String match = reg.getParen(i); // treat non-matching groups as empty matches if (match == null) { match = ""; } v.add(match); } return v; }