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
Difference between matches() and contains() Case sensitivity Searching an InputStream Splits Substitutions MatchResult exampleThe 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 .
matchesContainsExample.java demonstrates the difference between these
two methods.
caseTest.java shows how to do this.
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 .
You can experiment with split() and learn how to use it by compiling
splitExample.java and
running it with arguments of your choice.
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. |