Regex Quick Syntax Reference - Understanding and Using Regular Expressions

von: Zsolt Nagy

Apress, 2018

ISBN: 9781484238769 , 156 Seiten

Format: PDF, Online Lesen

Kopierschutz: Wasserzeichen

Mac OSX,Windows PC für alle DRM-fähigen eReader Apple iPad, Android Tablet PC's Online-Lesen für: Mac OSX,Linux,Windows PC

Preis: 39,99 EUR

eBook anfordern eBook anfordern

Mehr zum Inhalt

Regex Quick Syntax Reference - Understanding and Using Regular Expressions


 

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