/** * Returns the start index of the match. * * @return The index of the first character matched */ @Override public int start() { return matcher.start(); }
public int start(int group) { return matcher.start(group); }
/** * Returns the start index of the subsequence captured by the given * named-capturing group during the previous match operation. * * @param name The name of a named capturing group in this matcher's pattern * @return The index of the first character captured by the group, * or <tt>-1</tt> if the match was successful but the group * itself did not match anything */ @Override public int start(String name) { return matcher.start(name); }
public int start() { return matcher.start(); }
public int start(String name) { return matcher.start(name); }
/** * Returns the start index of the subsequence captured by the given group * during this match. * <br> * Capturing groups are indexed from left * to right, starting at one. Group zero denotes the entire pattern, so * the expression <i>m.</i><tt>start(0)</tt> is equivalent to * <i>m.</i><tt>start()</tt>. * * @param group The index of a capturing group in this matcher's pattern * @return The index of the first character captured by the group, * or <tt>-1</tt> if the match was successful but the group * itself did not match anything */ @Override public int start(int group) { return matcher.start(group); }
/** * Returns the start index of the subsequence captured by the given * named-capturing group during the previous match operation. * * @param name The name of a named capturing group in this matcher's pattern * @return The index of the first character captured by the group, * or <tt>-1</tt> if the match was successful but the group * itself did not match anything */ @Override public int start(String name) { Integer id = re.groupId(name); if (id == null) throw new IllegalArgumentException("<" + name + "> isn't defined"); return start(id); }
/** * Returns the start index of the subsequence captured by the given * named-capturing group during the previous match operation. * * @param name The name of a named capturing group in this matcher's pattern * @return The index of the first character captured by the group, * or <tt>-1</tt> if the match was successful but the group * itself did not match anything */ @Override public int start(String name) { Integer id = re.groupId(name); if (id == null) throw new IllegalArgumentException("<" + name + "> isn't defined"); return start(id); }
public static int indexOf(CharSequence text, Pattern regex) { matcher.setPattern(regex); matcher.setTarget(text); if(!matcher.find()) return -1; return matcher.start(); } public static int indexOf(CharSequence text, String regex)
public static int indexOf(CharSequence text, Pattern regex, int beginIndex) { matcher.setPattern(regex); matcher.setTarget(text); matcher.setPosition(beginIndex); if(!matcher.find()) return -1; return matcher.start(); } public static int indexOf(CharSequence text, String regex, int beginIndex)
public static int indexOf(CharSequence text, String regex) { matcher.setPattern(Pattern.compile(regex)); matcher.setTarget(text); if(!matcher.find()) return -1; return matcher.start(); }
public static int indexOf(CharSequence text, String regex, int beginIndex) { matcher.setPattern(Pattern.compile(regex)); matcher.setTarget(text); matcher.setPosition(beginIndex); if(!matcher.find()) return -1; return matcher.start(); } public static int indexOf(CharSequence text, Pattern regex)
/** * Replaces the next occurrence of a matcher's pattern in a matcher's target by a given substitution, appending the * result to a buffer but not writing the remainder of m's match to the end of dest. * <br> * The substitution starts from current matcher's position, current match not included. * <br> * You typically want to call {@code m.getGroup(MatchResult.TARGET, dest);} after you have called replaceStep() * until it returns false, which will fill in the remainder of the matching text into dest. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @return the number of replacements performed */ public static boolean replaceStep(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0, count = 1; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } return c > 0; }
/** * Replaces the next occurrence of a matcher's pattern in a matcher's target by a given substitution, appending the * result to a buffer but not writing the remainder of m's match to the end of dest. * <br> * The substitution starts from current matcher's position, current match not included. * <br> * You typically want to call {@code m.getGroup(MatchResult.TARGET, dest);} after you have called replaceStep() * until it returns false, which will fill in the remainder of the matching text into dest. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @return the number of replacements performed */ public static boolean replaceStep(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0, count = 1; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } return c > 0; }
/** * Replaces all occurrences of a matcher's pattern in a matcher's target * by a given substitution appending the result to a buffer.<br> * The substitution starts from current matcher's position, current match * not included. */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0; while (m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
/** * Replaces all occurrences of a matcher's pattern in a matcher's target * by a given substitution appending the result to a buffer.<br> * The substitution starts from current matcher's position, current match * not included. */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0; while (m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
/** * Replaces the first n occurrences of a matcher's pattern, where n is equal to count, * in a matcher's target by a given substitution, appending the result to a buffer. * <br> * The substitution starts from current matcher's position, current match not included. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @param count the number of replacements to attempt * @return the number of replacements performed */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest, int count) { boolean firstPass = true; int c = 0; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
/** * Replaces the first n occurrences of a matcher's pattern, where n is equal to count, * in a matcher's target by a given substitution, appending the result to a buffer. * <br> * The substitution starts from current matcher's position, current match not included. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @param count the number of replacements to attempt * @return the number of replacements performed */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest, int count) { boolean firstPass = true; int c = 0; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
boolean hasMatch = false; while (m.find()) { if (m.start() > 0) { hasMatch = true; break;
boolean hasMatch = false; while (m.find()) { if (m.start() > 0) { hasMatch = true; break;