Regex Quick Syntax Reference (eBook)
XI, 153 Seiten
Apress (Verlag)
978-1-4842-3876-9 (ISBN)
- Formulate an expression
- Work with arbitrary char classes, disjunctions, and operator precedence
- Execute regular expressions and visualize using finite state machines
- Deal with modifiers, including greedy and lazy loops
- Handle substring extraction from regex using Perl 6 capture groups, capture substrings, and reuse substrings
Zsolt Nagy is a web development team lead, mentor and software engineer living in Berlin, Germany. He programs with JavaScript, Perl and other open source web technologies. Zsolt is also experienced in using and teaching regular expressions using these technologies. He writes a blog about lessons learned while solving complex problems, experimenting with technology and teaching other people on how to improve their skills. As a software engineer, he continuously challenges himself to stick to the highest possible standards.
This quick guide to regular expressions is a condensed code and syntax reference for an important programming technique. It demonstrates regex syntax in a well-organized format that can be used as a handy reference, showing you how to execute regexes in many languages, including JavaScript, Python, Java, and C#.The Regex Quick Syntax Reference features short, focused code examples that show you how to use regular expressions to validate user input, split strings, parse input, and match patterns. Utilizing regular expressions to deal with search/replace and filtering data for backend coding is also covered. You won't find any bloated samples, drawn out history lessons, or witty stories in this book. What you will find is a language reference that is concise and highly accessible. The book is packed with useful information and is a must-have for any programmer.What You Will LearnFormulate an expressionWork with arbitrary char classes, disjunctions, and operator precedenceExecute regular expressions and visualize using finite state machinesDeal with modifiers, including greedy and lazy loops Handle substring extraction from regex using Perl 6 capture groups, capture substrings, and reuse substrings Who This Book Is ForIf you have dealt with at least one programming language, chances are you know enough to understand regular expressions, and the examples in this book will help you develop proficiency.
Zsolt Nagy is a web development team lead, mentor and software engineer living in Berlin, Germany. He programs with JavaScript, Perl and other open source web technologies. Zsolt is also experienced in using and teaching regular expressions using these technologies. He writes a blog about lessons learned while solving complex problems, experimenting with technology and teaching other people on how to improve their skills. As a software engineer, he continuously challenges himself to stick to the highest possible standards.
Table of Contents 4
About the Author 9
About the Technical Reviewer 10
Chapter 1: An Introduction to Regular Expressions 11
Why Are Regular Expressions Important? 11
What Are Regular Expressions? 12
Frustrations with Regular Expressions Arise from Lack of Taking Action 14
Regular Expressions Are Imperative 15
The Language Family of Regular Expressions 16
Summary 18
Chapter 2: Regex Syntax 101 19
Formulating an Expression 19
Literal Characters and Meta Characters 20
Arbitrary Character Class 23
Basic Concatenation 24
Alternative Execution 24
Operator Precedence and Parentheses 25
Anchored Start and End 25
Modifiers 29
Summary 31
Chapter 3: Executing Regular Expressions 32
Regular Expressions in JavaScript 32
RegExp Methods 34
String Methods Accepting Regular Expressions 35
Regex Modifiers 36
Global Matches 37
Multiline Matches 39
ES6 Unicode Regular Expressions 40
Sticky Matches 41
Summary 43
Other PCRE-Based Regex Environments 43
PHP 44
Python 46
Perl 5 49
Java 50
R 52
C# 53
Ruby 55
Golang 57
C++ 58
Summary 60
Chapter 4: Visualizing Regex Execution Using Finite State Machines 61
Regular Expressions Are Finite State Machines 61
Backtracking 63
Deterministic and Nondeterministic Regex Modeling 64
Basic Regex Simplifications 70
A Successful Match Is Cheaper Than Failure 71
Automatically Generating Regex FSMs 71
Summary 74
Chapter 5: Repeat Modifiers 75
Backtracking 76
Match at Least Once 78
Match at Most Once: Optionals 80
Match Any Number of Times 81
Fixed-Range Matching 82
Loop Exactly n Times 85
Greedy Repeat Modifiers 86
Lazy Repeat Modifiers 87
Possessive Repeat Modifiers 90
Summary 92
Chapter 6: Character Sets and Character Classes 93
Character Sets 93
Character Set Ranges 95
Exclusions from Character Sets 96
Character Set Classes 96
Concatenating Advanced Language Constructs 100
Summary 101
Chapter 7: Substring Extraction from Regular Expressions 102
Defining Capture Groups 103
Perl 6 Capture Groups 104
Retrieval of Captured Substrings 105
JavaScript 107
PHP 108
Python 109
Perl 5 110
Reusing Captured Substrings Within a Regex 111
Capture Groups and Performance 113
Extensions to Capture Groups 115
Summary 115
Chapter 8: Lookahead and Lookbehind 116
Lookahead 116
Lookbehind 119
Summary 120
Chapter 9: Maintaining Regular Expressions 121
Extended Mode 122
Regex Subroutines 124
PCRE Subroutines 125
Perl 6 Subroutines 126
Recursion and Circular References with Subroutines 127
Extended Mode, Subroutines, and Abstractions 127
Named Capture Groups 128
EMACS Named Capture Groups 128
PCRE Named Capture Groups 128
Perl 6 Named Capture Groups 131
Case Study: XRegExp Library for JavaScript 131
Summary 134
Chapter 10: Optimizing Regular Expressions 136
Summary of the Optimization Techniques 137
Making Character Classes More Specific 137
Repeating Character Class Loops 139
Use Possessive Repeat Modifiers Whenever Possible 140
Use Atomic Groups 141
Refactor for Optimization 143
Optimization Techniques Limit Nondeterministic Execution 143
Summary 144
Chapter 11: Parsing HTML Code and URL Query Strings with Regular Expressions 145
Parsing HTML Tags 145
Processing the Query String of a URL 148
Afterword: This Is Not the End, but the Beginning 150
“What If I Want to Learn More?” 152
Keep in Touch 153
Index 154
Erscheint lt. Verlag | 17.8.2018 |
---|---|
Zusatzinfo | XI, 153 p. 20 illus. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Mathematik / Informatik ► Informatik ► Programmiersprachen / -werkzeuge |
Mathematik / Informatik ► Informatik ► Software Entwicklung | |
Mathematik / Informatik ► Informatik ► Web / Internet | |
Schlagworte | C# • Code • C Sharp • Java • JavaScript • Perl • Perl 6 • programming • Python • Quick • Reference • regex • Regular Expressions • source code • Syntax • Text |
ISBN-10 | 1-4842-3876-1 / 1484238761 |
ISBN-13 | 978-1-4842-3876-9 / 9781484238769 |
Haben Sie eine Frage zum Produkt? |
Größe: 2,0 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich