Skip to content

Commit b2c5735

Browse files
updates for version 4.5
1 parent d2857b5 commit b2c5735

13 files changed

+574
-550
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Sundeep Agarwal
3+
Copyright (c) 2025 Sundeep Agarwal
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Learn Python Regular Expressions step-by-step from beginner to advanced levels w
44

55
<p align="center"><img src="./images/py_regex_ls.png" alt="Understanding Python re(gex)? ebook cover image" /></p>
66

7-
The book also includes exercises to test your understanding, which are presented together as a single file in this repo — [Exercises.md](./exercises/Exercises.md)
7+
The book also includes exercises to test your understanding, which are presented together as a single file in this repo — [Exercises.md](./exercises/Exercises.md).
88

99
For solutions to the exercises, see [Exercise_solutions.md](./exercises/Exercise_solutions.md).
1010

@@ -16,23 +16,18 @@ See [Version_changes.md](./Version_changes.md) to keep track of changes made to
1616

1717
# E-book
1818

19-
* You can purchase the pdf/epub versions of the book using these links
20-
* https://learnbyexample.gumroad.com/l/py_regex
19+
* You can purchase the pdf/epub versions of the book using these links:
2120
* https://leanpub.com/py_regex
21+
* https://learnbyexample.gumroad.com/l/py_regex
2222
* You can also get the book as part of these bundles:
23-
* **All books bundle** bundle from https://learnbyexample.gumroad.com/l/all-books
24-
* Includes all my programming books
23+
* **All books bundle** bundle from https://leanpub.com/b/learnbyexample-all-books or https://learnbyexample.gumroad.com/l/all-books
2524
* **Learn by example Python bundle** from https://leanpub.com/b/python-bundle or https://learnbyexample.gumroad.com/l/python-bundle
2625
* **Awesome Regex** bundle from https://leanpub.com/b/regex or https://learnbyexample.gumroad.com/l/regex
27-
* **The Indie Python Extravaganza** bundle from https://leanpub.com/b/theindiepythonextravaganza
28-
* Includes *Python 101*, *Pydon'ts*, *Python re(gex)?*, *Practice Python Projects* and *Clean Architectures in Python*
29-
* [Python 101 + Python re(gex)?](https://leanpub.com/b/python101pythonregex) or [Python 201: Intermediate Python + Python re(gex)?](https://leanpub.com/b/python201_and_regex)
30-
* Python 101/201 is authored by [Michael Driscoll](https://www.blog.pythonlibrary.org/)
31-
* See https://learnbyexample.github.io/books/ for list of other books
26+
* See https://learnbyexample.github.io/books/ for a list of other books
3227

33-
For a preview of the book, see [sample chapters](./sample_chapters/py_regex_sample.pdf)
28+
For a preview of the book, see [sample chapters](./sample_chapters/py_regex_sample.pdf).
3429

35-
The book can also be [viewed as a single markdown file in this repo](./py_regex.md). See my blogpost on [generating pdfs from markdown using pandoc](https://learnbyexample.github.io/customizing-pandoc/) if you are interested in the ebook creation process.
30+
The book can also be [viewed as a single markdown file in this repo](./py_regex.md). See my blogpost on [generating pdf/epub from markdown using pandoc](https://learnbyexample.github.io/customizing-pandoc/) if you are interested in the ebook creation process.
3631

3732
For the web version of the book, visit https://learnbyexample.github.io/py_regular_expressions/
3833

Resources_list.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
# Learning resources
1313

14-
**Note** that some of these resources are not specific to Python. So you'll have to adapt them to Python's syntax.
14+
Note that some of these resources are not specific to Python. So you'll have to adapt them to Python's syntax.
1515

1616
* [docs.python: Regular Expression HOWTO](https://docs.python.org/3/howto/regex.html)
1717
* [Python 3 Module of the Week: re](https://pymotw.com/3/re/index.html) — covers till Python version 3.7.9
1818
* [stackoverflow: python regex](https://stackoverflow.com/questions/tagged/python+regex?sort=votes&pageSize=15)
1919
* [PythonVerbalExpressions](https://github.com/VerbalExpressions/PythonVerbalExpressions) — construct regular expressions with natural language terms
2020
* [CommonRegex](https://github.com/madisonmay/CommonRegex) — collection of common regular expressions
21-
* [Awesome Regex](https://github.com/aloisdg/awesome-regex) — curated collection of libraries, tools, frameworks and software
21+
* [Awesome Regex](https://github.com/slevithan/awesome-regex) — curated collection of tools, tutorials, libraries, etc
2222
* [Generate strings that match a given regular expression](https://stackoverflow.com/q/492716/4082052)
2323
* [stackoverflow: regex FAQ](https://stackoverflow.com/q/22937618/4082052)
2424
* [stackoverflow: regex tag](https://stackoverflow.com/questions/tagged/regex) is a good source of exercise questions

Version_changes.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<br>
22

3+
### 4.5
4+
5+
* Python version updated to 3.13
6+
* deprecated features, SyntaxWarning, name change from `re.error` to `re.PatternError`
7+
* Corrected typos, updated descriptions, timing results and external links
8+
* Exercises are now numbered instead of using alphabets
9+
10+
<br>
11+
312
### 4.1
413

514
* Updated details for **re(gex)? playground** app

code_snippets/Gotchas.py

+4
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@
5656

5757
re.sub(r'(?i)key', r'(\g<0>)', 'KEY portkey oKey Keyed')
5858

59+
import re
60+
61+
re.sub(r'key', r'(\g<0>)', 'KEY portkey oKey Keyed', re.I)
62+

code_snippets/Lookarounds.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
re.sub(r'.(?<![pr].)', '*', 'spare')
2626

27-
re.sub(r'par(?!.*s)', '[\g<0>]', 'par spare part party')
27+
re.sub(r'par(?!.*s)', r'[\g<0>]', 'par spare part party')
2828

29-
re.sub(r'(?!.*s)par', '[\g<0>]', 'par spare part party')
29+
re.sub(r'(?!.*s)par', r'[\g<0>]', 'par spare part party')
3030

3131
re.sub(r'(?!\Z)\b(?<!\A)', ' ', 'output=num1+35*42/num2')
3232

@@ -36,7 +36,7 @@
3636

3737
re.findall(r'(?<=-)\d+(?=[:;])', '42 apple-5, fig3; x-83, y-20: f12')
3838

39-
re.sub(r'par(?=.*\bpart\b)', '[\g<0>]', 'par spare part party')
39+
re.sub(r'par(?=.*\bpart\b)', r'[\g<0>]', 'par spare part party')
4040

4141
re.findall(r'(?<=,)[^,]+(?=,)', '1,two,3,four,5')
4242

code_snippets/regex_module.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
regex.search(r'(?P<date>\d{4}-\d{2}-\d{2}).*(?&date)', row)[0]
2020

21-
## Set start of matching portion with \K
21+
## Set the start of matching portion with \K
2222

2323
regex.sub(r'\b\w\K\w*\W*', '', 'sea eat car rat eel tea')
2424

2525
s = 'cat scatter cater scat concatenate catastrophic catapult duplicate'
2626

27-
regex.sub(r'(cat.*?){2}\Kcat', '[\g<0>]', s, count=1)
27+
regex.sub(r'(cat.*?){2}\Kcat', r'[\g<0>]', s, count=1)
2828

29-
regex.sub(r'(cat.*?){2}\Kcat', '[\g<0>]', s)
29+
regex.sub(r'(cat.*?){2}\Kcat', r'[\g<0>]', s)
3030

3131
row = '421,cat,2425,42,5,cat,6,6,42,61,6,6,6,6,4'
3232

@@ -115,28 +115,28 @@
115115

116116
regex.findall(r'\((?:[^()]++|\([^()]++\))++\)', eqn2)
117117

118-
lvl2 = regex.compile('''
119-
\( #literal (
120-
(?: #start of non-capturing group
121-
[^()]++ #non-parentheses characters
122-
| #OR
123-
\([^()]++\) #level-one RE
124-
)++ #end of non-capturing group, 1 or more times
125-
\) #literal )
118+
lvl2 = regex.compile(r'''
119+
\( # literal (
120+
(?: # start of non-capturing group
121+
[^()]++ # non-parentheses characters
122+
| # OR
123+
\([^()]++\) # level-one RE
124+
)++ # end of non-capturing group, 1 or more times
125+
\) # literal )
126126
''', flags=regex.X)
127127

128128
lvl2.findall(eqn1)
129129

130130
lvl2.findall(eqn2)
131131

132-
lvln = regex.compile('''
133-
\( #literal (
134-
(?: #start of non-capturing group
135-
[^()]++ #non-parentheses characters
136-
| #OR
137-
(?0) #recursive call
138-
)++ #end of non-capturing group, 1 or more times
139-
\) #literal )
132+
lvln = regex.compile(r'''
133+
\( # literal (
134+
(?: # start of non-capturing group
135+
[^()]++ # non-parentheses characters
136+
| # OR
137+
(?0) # recursive call
138+
)++ # end of non-capturing group, 1 or more times
139+
\) # literal )
140140
''', flags=regex.X)
141141

142142
lvln.findall(eqn0)

0 commit comments

Comments
 (0)