ORO, Inc. Logo

CONTENTS

PREFACE

COPYRIGHT AND LICENSE

INTRODUCTION

Installation
Acknowledgements

FAQ

SYNTAX

What is a regular expression?
Perl5 regular expressions

THE INTERFACES

Pattern
PatternCompiler
PatternMatcher
MatchResult

THE CLASSES

Perl5Pattern
Perl5Compiler
Perl5Matcher
PatternMatcherInput
Perl5StreamInput
Util
Perl5Debug

SAMPLE PROGRAMS

MatchResult example
Difference between matches() and contains()
Case sensitivity
Searching an InputStream
Splits
Substitutions

APPENDIX

Package API reference (javadoc generated)
      

Sample Programs


MatchResult example

The main things to understand about the MatchResult class are that it stores the entire match and it stores offset information for the match and all its saved subgroups. The entire match is accessible through either the group() method (with an argument of 0) or the toString() method. Saved subgroups are accessible from the group() method. The beginOffset() and endOffset() methods return offsets relative to the beginning of the input while the begin() and end() methods return offsets relative to the beginning of a match. The end() and endOffset() methods return an offset 1 greater than the offset of the last character of a match.

For an example of the MatchResult methods, see matchResultExample.java .

Difference between matches() and contains()

It is easy to forget that the matches() method only tests for an EXACT match of the ENTIRE input whereas contains() searches for a match inside the input.

matchesContainsExample.java demonstrates the difference between these two methods.

Case sensitivity

By default, patterns are case sensitive. Patterns can be made case insensitive by calling the Perl5Compiler compile() method with the Perl5Compiler.CASE_INSENSITIVE_MASK flag set.

caseTest.java shows how to do this.

Searching an InputStream

One of the most useful OROMatcher TM features is its ability to search for a pattern in an InputStream without requiring the programmer to read the entire stream into memory first.

You can see how to make use of this feature, in addition to learning how to use backrefernces if you don't already know how, by examining streamInputExample.java .

Splits

The Util class provides methods for performing some functions commonly associated with regular expressions. The split() method provides all the functionality you may already be used to from using the Perl split() function.

You can experiment with split() and learn how to use it by compiling splitExample.java and running it with arguments of your choice.

Substitutions

Pattern substitution is a common operation to which regular expressions are applied. The Util class' substitute() method provides the rich functionality of the Perl s/ operator, including the interpolation of variables representing saved parenthesized groups.

Experimenting with substituteExample.java should give you a better understanding of the substitute() method.


Copyright © 1997 ORO, Inc. All rights reserved. Original Reusable Objects, ORO, the ORO logo, and "Component software for the Internet" are trademarks or registered trademarks of ORO, Inc. in the United States and other countries.
Java is a trademark of Sun Microsystems. All other trademarks are the property of their respective holders.