文档介绍:Mastering Regular Expressions
Powerful Techniques for Perl and Other Tools
Jeffrey . Friedl
O'REILLY
Cambridge • Köln • Paris • Sebastopol • Tokyo
[PU]O'Reilly[/PU][DP]1997[/DP]
Page iv
Mastering Regular Expressions
by Jeffrey . Friedl
Copyright © 1997 O'Reilly & Associates, Inc. All rights reserved.
Printed in the United States of America.
Published by O'Reilly & Associates, Inc., 101 Morris Street, Sebastopol, CA
95472.
Editor: Andy Oram
Production Editor: Jeffrey Friedl
Printing History:
January 1997: First Edition.
March 1997: Second printing; Minor corrections.
May 1997: Third printing; Minor corrections.
July 1997: Fourth printing; Minor corrections.
November 1997: Fifth printing; Minor corrections.
August 1998: Sixth printing; Minor corrections.
December 1998: Seventh printing; Minor corrections.
Nutshell Handbook and the Nutshell Handbook logo are registered trademarks
and The Java Series is a trademark of O'Reilly & Associates, Inc.
Many of the designations used by manufacturers and sellers to distinguish their
products are claimed as trademarks. Where those designations appear in this
book, and O'Reilly & Associates, Inc. was aware of a trademark claim, the
designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the
publisher assumes no responsibility for errors or omissions, or for damages
resulting from the use of the information contained herein.
Page V
Table of Contents
Preface xv
1: Introduction to Regular Expressions 1
Solving Real Problems 2
Regular Expressions as a Language 4
The Filename Analogy 4
The Language Analogy 5
The Regular-Expression Frame of Mind 6
Searching Text Files: Egrep 7
Egrep Metacharacters 8
Start and End of the Line 8
Character Classes 9
Matching Any Character—Dot 11
Alternation 12
Word Boundaries 14
In a Nutshell 15
Optional Items 16
Other Quantifiers: Repetition 17
Ignoring