RegularExpression
v1.0

RegularExpression
Class RE

java.lang.Object
  |
  +--RegularExpression.RE

public class RE
extends java.lang.Object

The RE class handles standard PERL-type regular expression operations.

RE pattern matching and escape characters list:
 /d        ANY DIGIT
 /D        ANY NON-DIGIT
 /s        ANY TYPE OF WHITESPACE
 /S        ANY TYPE OF NON-WHITESPACE
 /w        ANY TYPE OF ALPHANUMERIC
 /W        ANY TYPE OF NON-ALPHANUMERIC
 .         ANY NON NEWLINE CHARACTER
 
 #x[0-9A-F]+ HEX REPRESENTATION OF A CHARACTER
 
 /?        WHERE ? IS ANY OTHER CHARACTER YIELDS THAT CHARACTER
 
 *         0 OR MORE TIMES
 +         1 OR MORE TIMES
 ?         0 OR 1 TIMES
 {M}       M TIMES
 {M,}      AT LEAST M TIMES
 {M,N}     AT LEAST M AND AT MOST N TIMES (N >= M)
 
 [al-z]    CHARACTER LIST, INDIVIDUAL CHARACTERS OR CHARACTER RANGES

Since:
JDK1.3.1

Constructor Summary
RE()
          Empty constructor.
RE(java.lang.String re, boolean casesensitive)
          Contructs a regular expression handler with the specified regular expression (as a string) and a boolean denoting case-sensitivity for operations.
 
Method Summary
 boolean beginningMatches(java.lang.String input)
          Returns a boolean value specifying whether the beginning of the specified string matches the regular expression or not.
 java.lang.Object[] beginningMatchesWithLength(java.lang.String input)
          Returns a boolean value specifying whether the beginning of the specified string matches the regular expression or not.
 RegularExpression.NFA getAutomaton()
          Returns the regular expression automaton.
 int indexOf(java.lang.String input, int offset)
          Returns the index of the first instance of the regular expression after the offset.
 boolean matches(java.lang.String input)
          Returns a boolean value specifying whether the specified string matches the regular expression or not.
 java.lang.Object[] matchesWithFailPoint(java.lang.String input)
          Returns a boolean value specifying whether the specified string matches the regular expression or not and if the string does not match it returns the position at which the string first failed.
 java.lang.Object[] nextTokenAndDelim(java.lang.String input, int offset)
          Returns the next token and delimiter in a specified string from the specified offset.
 java.lang.String replace(java.lang.String input, java.lang.String replacement)
          Replaces all matching substrings in a specified string with a specified replacement string.
 java.lang.String[] split(java.lang.String input)
          Splits the specified string into an array of tokens.
 java.lang.String toString()
          Returns a string formatted to look like a regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RE

public RE()
Empty constructor.

RE

public RE(java.lang.String re,
          boolean casesensitive)
   throws java.lang.Exception
Contructs a regular expression handler with the specified regular expression (as a string) and a boolean denoting case-sensitivity for operations. Example: RE regexp = new RE ("ab*c", true);
Parameters:
re - the regular expression string.
casesensitive - the flags used to specify case-sensitivity.
Method Detail

getAutomaton

public RegularExpression.NFA getAutomaton()
Returns the regular expression automaton.
Returns:
the regular expression automaton.

nextTokenAndDelim

public java.lang.Object[] nextTokenAndDelim(java.lang.String input,
                                            int offset)
Returns the next token and delimiter in a specified string from the specified offset. The delimiter is the first portion of text that matches the regular expression. The token is the text immediately preceeding the delimiter.
Parameters:
input - the string to be parsed.
offset - the offset from the beginning of the input string.
Returns:
an Object array with three elements (int, String, String): the index of the character following the delimiter (the next offset), the token string, and the delimiter string (null if none exists). Returns null if at the end of input string.

beginningMatches

public boolean beginningMatches(java.lang.String input)
Returns a boolean value specifying whether the beginning of the specified string matches the regular expression or not.
Parameters:
input - the string to be tested.
Returns:
the value specifying whether the string matched or not.

beginningMatchesWithLength

public java.lang.Object[] beginningMatchesWithLength(java.lang.String input)
Returns a boolean value specifying whether the beginning of the specified string matches the regular expression or not.
Parameters:
input - the string to be tested.
Returns:
an Object array with two elements (boolean, int): the value specifying whether the beginning matched or not, the length of the matched substring if one was found.

matches

public boolean matches(java.lang.String input)
Returns a boolean value specifying whether the specified string matches the regular expression or not. This is the primary matches function, used by end-user programmers.
Parameters:
input - the string to be tested.
Returns:
the value specifying whether the string matched or not.

matchesWithFailPoint

public java.lang.Object[] matchesWithFailPoint(java.lang.String input)
Returns a boolean value specifying whether the specified string matches the regular expression or not and if the string does not match it returns the position at which the string first failed. This is the secondary matches function that is used by developers looking to expand the RegularExpression package.
Parameters:
input - the string to be tested.
Returns:
an Object array with two elements (boolean, int): the value specifying whether the string matched or not, the first point of failure (if applicable).

indexOf

public int indexOf(java.lang.String input,
                   int offset)
Returns the index of the first instance of the regular expression after the offset.
Parameters:
input - the input string.
offset - the offset of the input string.
Returns:
the index result or -1 if no index is found.

replace

public java.lang.String replace(java.lang.String input,
                                java.lang.String replacement)
Replaces all matching substrings in a specified string with a specified replacement string.
Parameters:
input - the string to be manipulated.
replacement - the string to replace matching portions.
Returns:
the string after all replacements have been made.

split

public java.lang.String[] split(java.lang.String input)
Splits the specified string into an array of tokens.
Parameters:
input - the string to be parsed.
Returns:
an array of tokens.

toString

public java.lang.String toString()
Returns a string formatted to look like a regular expression.
Overrides:
toString in class java.lang.Object
Returns:
a string formatted to look like a regular expression.

RegularExpression
v1.0