正则表达式Cookbook(影印版)
正则表达式Cookbook(影印版)
Jan Goyvaerts, Steven Levithan
出版时间:2009年12月
页数:493
本书提供了超过100条的锦囊妙计,帮助你利用正则表达式处理数据、操纵文本。每位程序员都能找到正则表达式的用武之地,但想要充分发挥它的威力却未必容易。纵使经验丰富的用户也常会遇到性能不佳、误判、漏判或者令人费解的错误。《正则表达式Cookbook》对涉及此工具的最常见任务做了逐步讲解,此外还包括在C#、Java、JavaScript、Perl、PHP、Python、Ruby和VB.NET语言中使用正则表达式的诀窍。
阅读本书,你将:
· 通过简洁的教程理解正则表达式的基本原理
· 在多种编程和脚本语言中高效地应用正则表达式
· 学习如何验证和格式化输入
· 操纵单词、行、特殊字符和数值
· 找到在URL、路径、标记和数据交换中使用正则表达式的方法
· 学习更高级的正则表达式特性
· 理解在不同语言中正则表达式的应用程序接口、语法和行为的不同
· 针对特定需要,编写更加优化的正则表达式
无论你是初学者还是经验丰富的用户,《正则表达式Cookbook》都将有助于你对这一独特而不可替代的工具的理解。你将学到功能强大的新技巧,避免和语言相关的陷阱,利用这一经过实践检验的方法解决现实世界中的难题,从而节省宝贵的时间。
“这是一本精心打造的著作,内容翔实。我仅仅读了介绍的章节就学会了一些新技巧。”
——Nikolaj Lindberg,计算机语言学家,STTS Speech Technology Services

“《正则表达式Cookbook》对当前面临的问题做出了优雅的解答。总之,我对这些技巧之详尽感到震惊。”
——Zak Greant,开放技术倡导者和战略家
Jan Goyvaerts经营Just Great Software软件公司,在这家公司他负责设计和开发一些最流行的正则表达式软件。
Steven Levithan是一位JavaScript正则表达式权威专家,同时他还负责一个以正则表达式内容为中心的流行博客。
  1. Preface
  2. 1. Introduction to Regular Expressions
  3. Regular Expressions Defined
  4. Searching and Replacing with Regular Expressions
  5. Tools for Working with Regular Expressions
  6. 2. Basic Regular Expression Skills
  7. 2.1 Match Literal Text
  8. 2.2 Match Nonprintable Characters
  9. 2.3 Match One of Many Characters
  10. 2.4 Match Any Character
  11. 2.5 Match Something at the Start and/or the End of a Line
  12. 2.6 Match Whole Words
  13. 2.7 Unicode Code Points, Properties, Blocks, and Scripts
  14. 2.8 Match One of Several Alternatives
  15. 2.9 Group and Capture Parts of the Match
  16. 2.10 Match Previously Matched Text Again
  17. 2.11 Capture and Name Parts of the Match
  18. 2.12 Repeat Part of the Regex a Certain Number of Times
  19. 2.13 Choose Minimal or Maximal Repetition
  20. 2.14 Eliminate Needless Backtracking
  21. 2.15 Prevent Runaway Repetition
  22. 2.16 Test for a Match Without Adding It to the Overall Match
  23. 2.17 Match One of Two Alternatives Based on a Condition
  24. 2.18 Add Comments to a Regular Expression
  25. 2.19 Insert Literal Text into the Replacement Text
  26. 2.20 Insert the Regex Match into the Replacement Text
  27. 2.21 Insert Part of the Regex Match into the Replacement Text
  28. 2.22 Insert Match Context into the Replacement Text
  29. 3. Programming with Regular Expressions
  30. Programming Languages and Regex Flavors
  31. 3.1 Literal Regular Expressions in Source Code
  32. 3.2 Import the Regular Expression Library
  33. 3.3 Creating Regular Expression Objects
  34. 3.4 Setting Regular Expression Options
  35. 3.5 Test Whether a Match Can Be Found Within a Subject String
  36. 3.6 Test Whether a Regex Matches the Subject String Entirely
  37. 3.7 Retrieve the Matched Text
  38. 3.8 Determine the Position and Length of the Match
  39. 3.9 Retrieve Part of the Matched Text
  40. 3.10 Retrieve a List of All Matches
  41. 3.11 Iterate over All Matches
  42. 3.12 Validate Matches in Procedural Code
  43. 3.13 Find a Match Within Another Match
  44. 3.14 Replace All Matches
  45. 3.15 Replace Matches Reusing Parts of the Match
  46. 3.16 Replace Matches with Replacements Generated in Code
  47. 3.17 Replace All Matches Within the Matches of Another Regex
  48. 3.18 Replace All Matches Between the Matches of Another Regex
  49. 3.19 Split a String
  50. 3.20 Split a String, Keeping the Regex Matches
  51. 3.21 Search Line by Line
  52. 4. Validation and Formatting
  53. 4.1 Validate Email Addresses
  54. 4.2 Validate and Format North American Phone Numbers
  55. 4.3 Validate International Phone Numbers
  56. 4.4 Validate Traditional Date Formats
  57. 4.5 Accurately Validate Traditional Date Formats
  58. 4.6 Validate Traditional Time Formats
  59. 4.7 Validate ISO 8601 Dates and Times
  60. 4.8 Limit Input to Alphanumeric Characters
  61. 4.9 Limit the Length of Text
  62. 4.10 Limit the Number of Lines in Text
  63. 4.11 Validate Affirmative Responses
  64. 4.12 Validate Social Security Numbers
  65. 4.13 Validate ISBNs
  66. 4.14 Validate ZIP Codes
  67. 4.15 Validate Canadian Postal Codes
  68. 4.16 Validate U.K. Postcodes
  69. 4.17 Find Addresses with Post Office Boxes
  70. 4.18 Reformat Names From “FirstName LastName” to “LastName,
  71. FirstName”
  72. 4.19 Validate Credit Card Numbers
  73. 4.20 European VAT Numbers
  74. 5. Words, Lines, and Special Characters
  75. 5.1 Find a Specific Word
  76. 5.2 Find Any of Multiple Words
  77. 5.3 Find Similar Words
  78. 5.4 Find All Except a Specific Word
  79. 5.5 Find Any Word Not Followed by a Specific Word
  80. 5.6 Find Any Word Not Preceded by a Specific Word
  81. 5.7 Find Words Near Each Other
  82. 5.8 Find Repeated Words
  83. 5.9 Remove Duplicate Lines
  84. 5.10 Match Complete Lines That Contain a Word
  85. 5.11 Match Complete Lines That Do Not Contain a Word
  86. 5.12 Trim Leading and Trailing Whitespace
  87. 5.13 Replace Repeated Whitespace with a Single Space
  88. 5.14 Escape Regular Expression Metacharacters
  89. 6. Numbers
  90. 6.1 Integer Numbers
  91. 6.2 Hexadecimal Numbers
  92. 6.3 Binary Numbers
  93. 6.4 Strip Leading Zeros
  94. 6.5 Numbers Within a Certain Range
  95. 6.6 Hexadecimal Numbers Within a Certain Range
  96. 6.7 Floating Point Numbers
  97. 6.8 Numbers with Thousand Separators
  98. 6.9 Roman Numerals
  99. 7. URLs, Paths, and Internet Addresses
  100. 7.1 Validating URLs
  101. 7.2 Finding URLs Within Full Text
  102. 7.3 Finding Quoted URLs in Full Text
  103. 7.4 Finding URLs with Parentheses in Full Text
  104. 7.5 Turn URLs into Links
  105. 7.6 Validating URNs
  106. 7.7 Validating Generic URLs
  107. 7.8 Extracting the Scheme from a URL
  108. 7.9 Extracting the User from a URL
  109. 7.10 Extracting the Host from a URL
  110. 7.11 Extracting the Port from a URL
  111. 7.12 Extracting the Path from a URL
  112. 7.13 Extracting the Query from a URL
  113. 7.14 Extracting the Fragment from a URL
  114. 7.15 Validating Domain Names
  115. 7.16 Matching IPv4 Addresses
  116. 7.17 Matching IPv6 Addresses
  117. 7.18 Validate Windows Paths
  118. 7.19 Split Windows Paths into Their Parts
  119. 7.20 Extract the Drive Letter from a Windows Path
  120. 7.21 Extract the Server and Share from a UNC Path
  121. 7.22 Extract the Folder from a Windows Path
  122. 7.23 Extract the Filename from a Windows Path
  123. 7.24 Extract the File Extension from a Windows Path
  124. 7.25 Strip Invalid Characters from Filenames
  125. 8. Markup and Data Interchange
  126. 8.1 Find XML-Style Tags
  127. 8.2 Replace <b> Tags with <strong>
  128. 8.3 Remove All XML-Style Tags Except <em> and <strong>
  129. 8.4 Match XML Names
  130. 8.5 Convert Plain Text to HTML by Adding <p> and <br> Tags
  131. 8.6 Find a Specific Attribute in XML-Style Tags
  132. 8.7 Add a cellspacing Attribute to <table> Tags That Do Not Already
  133. Include It
  134. 8.8 Remove XML-Style Comments
  135. 8.9 Find Words Within XML-Style Comments
  136. 8.10 Change the Delimiter Used in CSV Files
  137. 8.11 Extract CSV Fields from a Specific Column
  138. 8.12 Match INI Section Headers
  139. 8.13 Match INI Section Blocks
  140. 8.14 Match INI Name-Value Pairs
  141. Index
书名:正则表达式Cookbook(影印版)
国内出版社:东南大学出版社
出版时间:2009年12月
页数:493
书号:978-7-5641-1931-7
原版书出版商: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.
 
 
The image on the cover of Regular Expressions Cookbook is a musk shrew (genus
Crocidura, family Soricidae). Several types of musk shrews exist, including white- and
red-toothed shrews, gray musk shrews, and red musk shrews. The shrew is native to
South Africa and India.
While several physical characteristics distinguish one type of shrew from another, all
shrews share certain commonalities. For instance, shrews are thought to be the smallest
insectivores in the world, and all have stubby legs, five claws on each foot, and an
elongated snout with tactile hairs. Differences include color variations among their
teeth (most noticeably in the aptly named white- and red-toothed shrews) and in the
color of their fur, which ranges from red to brown to gray.
Though the shrew usually forages for insects, it will also help farmers keep vermin in
check by eating mice or other small rodents in their fields.
Many musk shrews give off a strong, musky odor (hence their common name), which
they use to mark their territory. At one time it was rumored that the musk shrew’s scent
was so strong that it would permeate any wine or beer bottles that the shrew happened
to pass by, thus giving the liquor a musky taint, but the rumor has since proved to be
false.