Regular Expressions Cookbook

Regular Expressions Cookbook

Jan Goyvaerts

Language: English

Pages: 612

ISBN: 1449319432

Format: PDF / Kindle (mobi) / ePub


Take the guesswork out of using regular expressions. With more than 140 practical recipes, this cookbook provides everything you need to solve a wide range of real-world problems. Novices will learn basic skills and tools, and programmers and experienced users will find a wealth of detail. Each recipe provides samples you can use right away.

This revised edition covers the regular expression flavors used by C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET. You’ll learn powerful new tricks, avoid flavor-specific gotchas, and save valuable time with this huge library of practical solutions.

  • Learn regular expressions basics through a detailed tutorial
  • Use code listings to implement regular expressions with your language of choice
  • Understand how regular expressions differ from language to language
  • Handle common user input with recipes for validation and formatting
  • Find and manipulate words, special characters, and lines of text
  • Detect integers, floating-point numbers, and other numerical formats
  • Parse source code and process log files
  • Use regular expressions in URLs, paths, and IP addresses
  • Manipulate HTML, XML, and data exchange formats
  • Discover little-known regular expression tricks and techniques

jQuery Cookbook: Solutions & Examples for jQuery Developers

Professional jQuery

Professional jQuery

CSS Pocket Reference

Network Backup with Bacula How-To: Create an autonomous backup solution for your computer network using practical, hands-on recipes

Just Give Money to the Poor: The Development Revolution from the Global South

 

 

 

 

 

 

 

 

 

 

 

it easy to match anything except a specific character, you can’t just write ‹[^cat]› to match anything except the word cat. ‹[^cat]› is a valid regex, but it matches any character except c, a, or t. Hence, although ‹\b[^cat]+\b› would avoid matching the word cat, it wouldn’t match the word cup either, because it contains the forbidden letter c. The regular expression ‹\b[^c][^a][^t]\w*› is no good either, because it would reject any word with c as its first letter, a as its second letter,

backreference, such as ‹\k› (.NET, PCRE 7, Perl 5.10) or ‹(?P=name)› (PCRE 4 and higher, Perl 5.10, Python) lets you re-match text that has already been matched by a named capturing group. A subroutine such as ‹(?&name)› allows you to reuse the actual pattern contained within the corresponding group. You can’t use a backreference here, because that would only allow re-matching words that have already been matched. The subroutines within the conditional at the end of the regex match

signed word): ^(3276[0-7]|327[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|↵ [1-9][0-9]{1,3}|[0-9])$ Regex options: None Regex flavors: .NET, Java, JavaScript, PCRE, Perl, Python, Ruby –32768 to 32767 (signed word): ^(3276[0-7]|327[0-5][0-9]|32[0-6][0-9]{2}|3[01][0-9]{3}|[12][0-9]{4}|↵ [1-9][0-9]{1,3}|[0-9]|-(3276[0-8]|327[0-5][0-9]|32[0-6][0-9]{2}|↵ 3[01][0-9]{3}|[12][0-9]{4}|[1-9][0-9]{1,3}|[0-9]))$ Regex options: None Regex flavors: .NET, Java, JavaScript, PCRE, Perl, Python,

Free-spacing Regex flavors: .NET, Java, PCRE, Perl, Python, Ruby Discussion Free-spacing mode Regular expressions can quickly become complicated and difficult to understand. Just as you should comment source code, you should comment all but the most trivial regular expressions. All regular expression flavors in this book, except JavaScript, offer an alternative regular expression syntax that makes it very easy to clearly comment your regular expressions. You can enable this syntax by

to check whether a match can be found for a particular regular expression in a particular string. A partial match is sufficient. For instance, the regex ‹regex●pattern› partially matches The regex pattern can be found. You don’t care about any of the details of the match. You just want to know whether the regex matches the string. Solution C# For quick one-off tests, you can use the static call: bool foundMatch = Regex.IsMatch(subjectString, " regex pattern"); If the regex is provided by

Download sample

Download