Regsub
class provides an iterator-like object to
/// extract the matched and unmatched portions of a string with respect to
/// a given regular expression.
/// /// After each match is found, the portions of the string already /// checked are not searched again -- searching for the next match will /// begin at the character just after where the last match ended. ///
/// Here is an example of using Regsub to replace all "%XX" sequences in /// a string with the ASCII character represented by the hex digits "XX": ///
/// public static void /// main(String[] args) /// throws Exception /// { /// Regexp re = new Regexp("%[a-fA-F0-9][a-fA-F0-9]"); /// Regsub rs = new Regsub(re, args[0]); /// /// StringBuffer sb = new StringBuffer(); /// /// while (rs.nextMatch()) { /// sb.append(rs.skipped()); /// /// String match = rs.matched(); /// /// int hi = Character.digit(match.charAt(1), 16); /// int lo = Character.digit(match.charAt(2), 16); /// sb.append((char) ((hi << 4) | lo)); /// } /// sb.append(rs.rest()); /// /// System.out.println(sb); /// } ////// ///
Regsub
that can be used to step
/// through the given string, finding each substring that matches
/// the given regular expression.
///
/// Regexp
contains two substitution methods,
/// sub
and subAll
, that can be used instead
/// of Regsub
if just simple substitutions are being done.
///
///
skipped
, matched
, etc. to query attributes
/// of the matched region.
/// /// Calling this function again will search for the next match, beginning /// at the character just after where the last match ended. /// ///
true
if a match was found, false
/// if there are no more matches.
/// /// This method can be used extract all the portions of string that /// didn't match the regular expression. /// ///
nextMatch
.
///
/// nextMatch
.
///
/// null
if the given subexpression did not
/// exist or did not match.
/// rest
/// gets shorter. When nextMatch
returns false
,
/// then this method will return the rest of the string that can't be
/// matched.
///
///