Regular Expresion Cookbook

Páginas: 399 (99715 palabras) Publicado: 16 de octubre de 2012
Regular Expressions Cookbook

Regular Expressions Cookbook

Jan Goyvaerts and Steven Levithan

Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo

Regular Expressions Cookbook
by Jan Goyvaerts and Steven Levithan
Copyright © 2009 Jan Goyvaerts and Steven Levithan. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.

Editor: Andy Oram Production Editor: Sumita MukherjiCopyeditor: Genevieve d’Entremont Proofreader: Kiel Van Horn Printing History:
May 2009: First Edition.

Indexer: Seth Maislin Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano

Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Regular Expressions Cookbook, the image of a musk shrew andrelated trade dress are trademarks of O’Reilly Media, 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 Media, 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 thisbook, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.

TM

This book uses RepKover™, a durable and flexible lay-flat binding.
ISBN: 978-0-596-52068-7 [M] 1242318889

Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . ix 1. Introduction to Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Regular Expressions Defined Searching and Replacing with Regular Expressions Tools for Working with Regular Expressions 1 5 7

2. Basic Regular Expression Skills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . 25
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 2.18 2.19 2.20 2.21 2.22 Match Literal Text Match Nonprintable Characters Match One of Many Characters Match Any Character Match Something at the Start and/or the End of a Line Match Whole Words Unicode Code Points, Properties, Blocks, and Scripts Match One of Several Alternatives Group and CaptureParts of the Match Match Previously Matched Text Again Capture and Name Parts of the Match Repeat Part of the Regex a Certain Number of Times Choose Minimal or Maximal Repetition Eliminate Needless Backtracking Prevent Runaway Repetition Test for a Match Without Adding It to the Overall Match Match One of Two Alternatives Based on a Condition Add Comments to a Regular Expression Insert Literal Textinto the Replacement Text Insert the Regex Match into the Replacement Text Insert Part of the Regex Match into the Replacement Text Insert Match Context into the Replacement Text 26 28 30 34 36 41 43 55 57 60 62 64 67 70 72 75 81 83 85 87 88 92

v

3. Programming with Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Programming Languages and RegexFlavors 3.1 Literal Regular Expressions in Source Code 3.2 Import the Regular Expression Library 3.3 Creating Regular Expression Objects 3.4 Setting Regular Expression Options 3.5 Test Whether a Match Can Be Found Within a Subject String 3.6 Test Whether a Regex Matches the Subject String Entirely 3.7 Retrieve the Matched Text 3.8 Determine the Position and Length of the Match 3.9 Retrieve Part...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Expresiones regular
  • Expresion Regular
  • Definicion de expresion regular
  • Reguladores
  • Reguladores
  • regulador
  • Regulaciones
  • Reguladores

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS