正则表达式Cookbook(第二版,影印版)
出版时间:2013年06月
页数:612
“正则表达式是一门永不过期的技术,而这本《正则表达式Cookbook》将是接下来若干年里知识和灵感的来源。”
——Ben Nadel
Epicenter咨询公司的首席软件工程师
再也不用猜测正则表达式的含义了。通过超过140个验证过的例子,本手册将为你提供一切所需来解决大量的实际问题。初学者可以从中学到基本的技能和工具,而程序员和有经验的用户会获益良多。每个例子都包含了你可以立刻使用的技巧。
本修订版本包括了在C#,Java,JavaScript,Perl, PHP, Python, Ruby和VB.NET中使用的多种不同的正则表达式。你将学到强大的新技能,避免那些在不同语言中使用正则表达式可能遇到的陷阱。通过这本包含大量实践方案的书籍,你将节省宝贵的时间。
· 通过细致的讲解来学习正则表达式的基础知识
· 根据代码清单,使用你所选择的语言来实现正则表达式
· 理解正则表达式在不同语言中的差异
· 在多个实例中验证和格式化常见的用户输入
· 查找和操纵单词、特殊字符以及多行文本
· 判断整数、浮点数和其他数字格式
· 在URL、文件路径和IP地址上运用正则表达式
· 操纵HTML、XML和数据交换格式
· 探讨少为人知的正则表达式窍门和技术
Jan Goyvaerts管理着Just Great Software公司,他设计和开发了一些最流行的正则表达式软件。
Steven Levithan是杰出的JavaScript正则表达式专家,同时他也是多个开源正则表达式工具的编写者。
- Chapter 1: Introduction to Regular Expressions
- Regular Expressions Defined
- Search and Replace with Regular Expressions
- Tools for Working with Regular Expressions
- Chapter 2: Basic Regular Expression Skills
- 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, Categories, Blocks, and Scripts
- Match One of Several Alternatives
- Group and Capture Parts 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 Text into 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
- Chapter 3: Programming with Regular Expressions
- Programming Languages and Regex Flavors
- Literal Regular Expressions in Source Code
- Import the Regular Expression Library
- Create Regular Expression Objects
- Set Regular Expression Options
- Test If a Match Can Be Found Within a Subject String
- Test Whether a Regex Matches the Subject String Entirely
- Retrieve the Matched Text
- Determine the Position and Length of the Match
- Retrieve Part of the Matched Text
- Retrieve a List of All Matches
- Iterate over All Matches
- Validate Matches in Procedural Code
- Find a Match Within Another Match
- Replace All Matches
- Replace Matches Reusing Parts of the Match
- Replace Matches with Replacements Generated in Code
- Replace All Matches Within the Matches of Another Regex
- Replace All Matches Between the Matches of Another Regex
- Split a String
- Split a String, Keeping the Regex Matches
- Search Line by Line
- Construct a Parser
- Chapter 4: Validation and Formatting
- Validate Email Addresses
- Validate and Format North American Phone Numbers
- Validate International Phone Numbers
- Validate Traditional Date Formats
- Validate Traditional Date Formats, Excluding Invalid Dates
- Validate Traditional Time Formats
- Validate ISO 8601 Dates and Times
- Limit Input to Alphanumeric Characters
- Limit the Length of Text
- Limit the Number of Lines in Text
- Validate Affirmative Responses
- Validate Social Security Numbers
- Validate ISBNs
- Validate ZIP Codes
- Validate Canadian Postal Codes
- Validate U.K. Postcodes
- Find Addresses with Post Office Boxes
- Reformat Names From “FirstName LastName” to “LastName, FirstName”
- Validate Password Complexity
- Validate Credit Card Numbers
- European VAT Numbers
- Chapter 5: Words, Lines, and Special Characters
- Find a Specific Word
- Find Any of Multiple Words
- Find Similar Words
- Find All Except a Specific Word
- Find Any Word Not Followed by a Specific Word
- Find Any Word Not Preceded by a Specific Word
- Find Words Near Each Other
- Find Repeated Words
- Remove Duplicate Lines
- Match Complete Lines That Contain a Word
- Match Complete Lines That Do Not Contain a Word
- Trim Leading and Trailing Whitespace
- Replace Repeated Whitespace with a Single Space
- Escape Regular Expression Metacharacters
- Chapter 6: Numbers
- Integer Numbers
- Hexadecimal Numbers
- Binary Numbers
- Octal Numbers
- Decimal Numbers
- Strip Leading Zeros
- Numbers Within a Certain Range
- Hexadecimal Numbers Within a Certain Range
- Integer Numbers with Separators
- Floating-Point Numbers
- Numbers with Thousand Separators
- Add Thousand Separators to Numbers
- Roman Numerals
- Chapter 7: Source Code and Log Files
- Keywords
- Identifiers
- Numeric Constants
- Operators
- Single-Line Comments
- Multiline Comments
- All Comments
- Strings
- Strings with Escapes
- Regex Literals
- Here Documents
- Common Log Format
- Combined Log Format
- Broken Links Reported in Web Logs
- Chapter 8: URLs, Paths, and Internet Addresses
- Validating URLs
- Finding URLs Within Full Text
- Finding Quoted URLs in Full Text
- Finding URLs with Parentheses in Full Text
- Turn URLs into Links
- Validating URNs
- Validating Generic URLs
- Extracting the Scheme from a URL
- Extracting the User from a URL
- Extracting the Host from a URL
- Extracting the Port from a URL
- Extracting the Path from a URL
- Extracting the Query from a URL
- Extracting the Fragment from a URL
- Validating Domain Names
- Matching IPv4 Addresses
- Matching IPv6 Addresses
- Validate Windows Paths
- Split Windows Paths into Their Parts
- Extract the Drive Letter from a Windows Path
- Extract the Server and Share from a UNC Path
- Extract the Folder from a Windows Path
- Extract the Filename from a Windows Path
- Extract the File Extension from a Windows Path
- Strip Invalid Characters from Filenames
- Chapter 9: Markup and Data Formats
- Processing Markup and Data Formats with Regular Expressions
- Find XML-Style Tags
- Replace <b> Tags with <strong>
- Remove All XML-Style Tags Except <em> and <strong>
- Match XML Names
- Convert Plain Text to HTML by Adding <p> and <br> Tags
- Decode XML Entities
- Find a Specific Attribute in XML-Style Tags
- Add a cellspacing Attribute to <table> Tags That Do Not Already Include It
- Remove XML-Style Comments
- Find Words Within XML-Style Comments
- Change the Delimiter Used in CSV Files
- Extract CSV Fields from a Specific Column
- Match INI Section Headers
- Match INI Section Blocks
- Match INI Name-Value Pairs
书名:正则表达式Cookbook(第二版,影印版)
国内出版社:东南大学出版社
出版时间:2013年06月
页数:612
书号:978-7-5641-4202-5
原版书书名:Regular Expressions Cookbook, 2nd Edition
原版书出版商:O'Reilly Media
Jan Goyvaerts
Regular Expressions Cookbook is written by Jan Goyvaerts and Steven Levithan, two
of the world’s experts on regular expressions.
Jan Goyvaerts runs Just Great Software, where he designs and develops some of the
most popular regular expression software. His products include RegexBuddy, the
world’s only regular expression editor that emulates the peculiarities of 15 regular expression
flavors, and PowerGREP, the most feature-rich grep tool for Microsoft
Windows.
Steven Levithan
Regular Expressions Cookbook is written by Jan Goyvaerts and Steven Levithan, two
of the world’s experts on regular expressions.
Steven Levithan is a leading JavaScript regular expression expert and runs a popular
regular expression centric blog at http://blog.stevenlevithan.com. Expanding his knowledge
of the regular expression flavor and library landscape has been one of his hobbies
for the last several years.