Contents | Package | Class | Tree | Deprecated | Index | Help XML for Java 1.0.4
PREV | NEXT SHOW LISTS | HIDE LISTS

Class com.ibm.xml.omake.Regexp

java.lang.Object
    |
    +----com.ibm.xml.omake.Regexp

public class Regexp
extends java.lang.Object
implements java.io.Serializable
Regular expression matching using non-deterministic finate automaton (NFA).

Special characters are `. * + ? [ ( ) | \'.

.
Matches any one character.
[s-e]
...
[^s-e]
...
X|Y
...
X*
...
X+
...
X?
...
(X)
Grouping. "foo|bar" matches "fooar" or "fobar". If you want it matches "foo" or "bar", you must write "(foo|bar)".
a non-special character
Matches the character.
\ + a special character
...

Parensises make groups of in a regular expression and applications can know where in target text each group matched with getMatchedBeginnig() getMatchedEnd() getMatchedString() after match() exactMatch(). The 0th group means whole of this regular expression. The Nth gorup is the inside of the Nth left parensis.

For instance, a regular expression is " *([^<:]*) *<([^>]*)> *" and target text is "From: TAMURA Kent <kent@trl.ibm.co.jp>"
getMatchedString(0): " TAMURA Kent <kent@trl.ibm.co.jp>"
getMatchedString(1): "TAMURA Kent"
getMatchedString(2): "kent@trl.ibm.co.jp"

Version:
Revision: 49 1.2 src/com/ibm/xml/omake/Regexp.java, xml4jsrc, xml4j-jtcsv, xml4j_1_0_4

Constructor Summary
 Regexp(java.lang.String regexp)
Constructor.
 

Method Summary
boolean  exactMatch(java.lang.String target)
 
int  getMatchedBeginning(int index)
Return a start position in the target text matched to specified regular expression group.
int  getMatchedEnd(int index)
Return an end position in the target text matched to specified regular expression group.
java.lang.String  getMatchedString(int index)
Return an substring of the target text matched to specified regular expression group.
int  getNumberOfGroups()
Return the number of regular expression groups.
static void  main(java.lang.String[] argv)
Sample entry.
int  match(java.lang.String target)
 
java.lang.String  toString()
Represents this instence in String.
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Regexp

public Regexp(java.lang.String regexp) throws RegexpParseException
Constructor.
Parameters:
regexp - A regular expression
Throws:
com.ibm.xml.omake.RegexParserException - regexp is wrong.
Method Detail

toString

public java.lang.String toString()
Represents this instence in String.
Overrides:
toString in class java.lang.Object

match

public int match(java.lang.String target)
Returns:
Offset of the start position in target

exactMatch

public boolean exactMatch(java.lang.String target)

getMatchedBeginning

public int getMatchedBeginning(int index)
Return a start position in the target text matched to specified regular expression group.

This method doesn't return valid value before calling match()/exactMatch().

Parameters:
index - Less than getNumberOfGroups().
See Also:
getMatchedEnd, getMatchedString, getNumberOfGroups

getMatchedEnd

public int getMatchedEnd(int index)
Return an end position in the target text matched to specified regular expression group.

This method doesn't return valid value before calling match()/exactMatch().

Parameters:
index - Less than getNumberOfGroups().
See Also:
getMatchedBeginning, getMatchedString, getNumberOfGroups

getMatchedString

public java.lang.String getMatchedString(int index)
Return an substring of the target text matched to specified regular expression group.

This method doesn't return valid value before calling match()/exactMatch().

Parameters:
index - Less than getNumberOfGroups().
See Also:
getMatchedBeginning, getMatchedEnd, getNumberOfGroups

getNumberOfGroups

public int getNumberOfGroups()
Return the number of regular expression groups. This method returns 1 when the regular expression has no parensis.
See Also:
getMatchedBeginning, getMatchedString, getMatchedEnd

main

public static void main(java.lang.String[] argv)
Sample entry. Usage: com.ibm.xml.omake.Regexp <regexp> <string>

Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS