Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 846838d

Browse files
updates for version 3.2
1 parent 8d26d74 commit 846838d

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

‎README.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ Please open an issue if you spot any typo/errors.
4141

4242
I'd also highly appreciate your feedback about the book.
4343

44-
Goodreads: https://www.goodreads.com/book/show/47142552-python-re-gex
45-
4644
Twitter: https://twitter.com/learn_byexample
4745

4846
<br>
@@ -73,13 +71,14 @@ Twitter: https://twitter.com/learn_byexample
7371
# Acknowledgements
7472

7573
* [Python documentation](https://docs.python.org/3/) — manuals and tutorials
76-
* [/r/learnpython/](https://www.reddit.com/r/learnpython/) and [/r/regex/](https://www.reddit.com/r/regex/) — helpful forums for beginners and experienced programmers alike
74+
* [/r/learnpython/](https://www.reddit.com/r/learnpython/), [/r/Python/](https://www.reddit.com/r/Python/) and [/r/regex/](https://www.reddit.com/r/regex/) — helpful forums for beginners and experienced programmers alike
7775
* [stackoverflow](https://stackoverflow.com/) — for getting answers to pertinent questions on Python and regular expressions
7876
* [tex.stackexchange](https://tex.stackexchange.com/) — for help on `pandoc` and `tex` related questions
7977
* Cover image: [draw.io](https://about.draw.io/), [tree icon](https://www.iconfinder.com/icons/3199231/ellipse_green_nature_tree_icon) by [Gopi Doraisamy](https://www.iconfinder.com/gopidoraisamy) under [Creative Commons Attribution 3.0 Unported](https://creativecommons.org/licenses/by/3.0/) and [wand icon](https://www.iconfinder.com/icons/1679640/design_magic_magician_tool_wand_icon) by [roundicons.com](https://www.iconfinder.com/roundicons)
8078
* [Warning](https://commons.wikimedia.org/wiki/File:Warning_icon.svg) and [Info](https://commons.wikimedia.org/wiki/File:Info_icon_002.svg) icons by [Amada44](https://commons.wikimedia.org/wiki/User:Amada44) under public domain
79+
* [pngquant](https://pngquant.org/) and [svgcleaner](https://github.com/RazrFalcon/svgcleaner) for optimizing images
8180
* [David Cortesi](https://leanpub.com/u/dcortesi) for helpful feedback on both the technical content and grammar issues
82-
* **Kye** for spotting a typo
81+
* **Kye** and [gmovchan](https://github.com/gmovchan)for spotting a typo
8382
* **Hugh**'s email exchanges helped me significantly to improve the presentation of concepts and exercises
8483
* [Christopher Patti](https://github.com/feoh) for reviewing the book, providing feedback and brightening the day with kind words
8584
* Users **73tada**, **DrBobHope**, **nlomb** and others for feedback in [this reddit thread](https://www.reddit.com/r/learnpython/comments/hmvnt1/my_python_regex_ebook_with_hundreds_of_examples/)

‎Version_changes.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<br>
22

3+
### 3.2
4+
5+
* Corrected typos in description, cheatsheet, exercises and solutions
6+
* Updated Acknowledgements section
7+
8+
<br>
9+
310
### 3.1
411

512
* Added real world regular expressions usage examples and overview of book in introduction chapter

‎exercises/Exercise_solutions.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,10 @@ The use of `.+` quantifier after `<` means that `<>` cannot be a possible match
713713
**n)** Convert the comma separated strings to corresponding `dict` objects as shown below.
714714

715715
```ruby
716-
>>> row1 = 'name:rohan,maths:75,phy:89'
717-
>>> row2 = 'name:rose,maths:88,phy:92'
716+
>>> row1 = 'name:rohan,maths:75,phy:89,'
717+
>>> row2 = 'name:rose,maths:88,phy:92,'
718718

719-
>>> pat = re.compile(r'([^:]+):([^,]+),?')
719+
>>> pat = re.compile(r'(.+?):(.+?),')
720720

721721
>>> {m[1]:m[2] for m in pat.finditer(row1)}
722722
{'name': 'rohan', 'maths': '75', 'phy': '89'}
@@ -920,10 +920,10 @@ inns
920920
```ruby
921921
>>> ip = 'price_42 roast^\t\n^-ice==cat\neast'
922922

923-
>>> re.split(r'[\s^=-]+', ip)
923+
>>> re.split(r'\W+', ip)
924924
['price_42', 'roast', 'ice', 'cat', 'east']
925925

926-
>>> re.split(r'([\s^=-]+)', ip)
926+
>>> re.split(r'(\W+)', ip)
927927
['price_42', ' ', 'roast', '^\t\n^-', 'ice', '==', 'cat', '\n', 'east']
928928
```
929929

@@ -1324,7 +1324,7 @@ In contrast, the negative lookarounds only ensure that there are no word charact
13241324

13251325
# Flags
13261326

1327-
**a)** Remove from first occurrence of `hat` to last occurrence of `ice` for the given input strings. Match these markers case insensitively.
1327+
**a)** Remove from first occurrence of `hat` to last occurrence of `it` for the given input strings. Match these markers case insensitively.
13281328

13291329
```ruby
13301330
>>> s1 = 'But Cool THAT\nsee What okay\nwow quite'

‎exercises/Exercises.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ mallet wallet malls
709709
**n)** Convert the comma separated strings to corresponding `dict` objects as shown below.
710710

711711
```ruby
712-
>>> row1 = 'name:rohan,maths:75,phy:89'
713-
>>> row2 = 'name:rose,maths:88,phy:92'
712+
>>> row1 = 'name:rohan,maths:75,phy:89,'
713+
>>> row2 = 'name:rose,maths:88,phy:92,'
714714

715715
>>> pat = re.compile() ##### add your solution here
716716

@@ -1297,7 +1297,7 @@ False
12971297

12981298
# Flags
12991299

1300-
**a)** Remove from first occurrence of `hat` to last occurrence of `ice` for the given input strings. Match these markers case insensitively.
1300+
**a)** Remove from first occurrence of `hat` to last occurrence of `it` for the given input strings. Match these markers case insensitively.
13011301

13021302
```ruby
13031303
>>> s1 = 'But Cool THAT\nsee What okay\nwow quite'

‎py_regex.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ If you have prior experience with a programming language, but new to Python, see
1616
* Code snippets shown are copy pasted from Python REPL shell and modified for presentation purposes. Some commands are preceded by comments to provide context and explanations. Blank lines have been added to improve readability. Error messages are shortened. `import` statements are skipped after initial use. And so on.
1717
* Unless otherwise noted, all examples and explanations are meant for **ASCII** characters.
1818
* External links are provided for further reading throughout the book. Not necessary to immediately visit them. They have been chosen with care and would help, especially during re-reads.
19-
* The [py_regular_expressions repo](https://github.com/learnbyexample/py_regular_expressions) has all the code snippets and files used in examples and exercises and other details related to the book. If you are not familiar with `git` command, click the **Clone** button on the webpage to get the files.
19+
* The [py_regular_expressions repo](https://github.com/learnbyexample/py_regular_expressions) has all the code snippets and files used in examples and exercises and other details related to the book. If you are not familiar with `git` command, click the **Code** button on the webpage to get the files.
2020

2121
## Acknowledgements
2222

2323
* [Python documentation](https://docs.python.org/3/) — manuals and tutorials
24-
* [/r/learnpython/](https://www.reddit.com/r/learnpython/) and [/r/regex/](https://www.reddit.com/r/regex/) — helpful forums for beginners and experienced programmers alike
24+
* [/r/learnpython/](https://www.reddit.com/r/learnpython/), [/r/Python/](https://www.reddit.com/r/Python/) and [/r/regex/](https://www.reddit.com/r/regex/) — helpful forums for beginners and experienced programmers alike
2525
* [stackoverflow](https://stackoverflow.com/) — for getting answers to pertinent questions on Python and regular expressions
2626
* [tex.stackexchange](https://tex.stackexchange.com/) — for help on `pandoc` and `tex` related questions
2727
* Cover image: [draw.io](https://about.draw.io/), [tree icon](https://www.iconfinder.com/icons/3199231/ellipse_green_nature_tree_icon) by [Gopi Doraisamy](https://www.iconfinder.com/gopidoraisamy) under [Creative Commons Attribution 3.0 Unported](https://creativecommons.org/licenses/by/3.0/) and [wand icon](https://www.iconfinder.com/icons/1679640/design_magic_magician_tool_wand_icon) by [roundicons.com](https://www.iconfinder.com/roundicons)
2828
* [Warning](https://commons.wikimedia.org/wiki/File:Warning_icon.svg) and [Info](https://commons.wikimedia.org/wiki/File:Info_icon_002.svg) icons by [Amada44](https://commons.wikimedia.org/wiki/User:Amada44) under public domain
29+
* [pngquant](https://pngquant.org/) and [svgcleaner](https://github.com/RazrFalcon/svgcleaner) for optimizing images
2930
* [David Cortesi](https://leanpub.com/u/dcortesi) for helpful feedback on both the technical content and grammar issues
30-
* **Kye** for spotting a typo
31+
* **Kye** and [gmovchan](https://github.com/gmovchan)for spotting a typo
3132
* **Hugh**'s email exchanges helped me significantly to improve the presentation of concepts and exercises
3233
* [Christopher Patti](https://github.com/feoh) for reviewing the book, providing feedback and brightening the day with kind words
3334
* Users **73tada**, **DrBobHope**, **nlomb** and others for feedback in [this reddit thread](https://www.reddit.com/r/learnpython/comments/hmvnt1/my_python_regex_ebook_with_hundreds_of_examples/)
@@ -41,8 +42,6 @@ I would highly appreciate if you'd let me know how you felt about this book, it
4142

4243
Issue Manager: [https://github.com/learnbyexample/py_regular_expressions/issues](https://github.com/learnbyexample/py_regular_expressions/issues)
4344

44-
Goodreads: https://www.goodreads.com/book/show/47142552-python-re-gex
45-
4645
E-mail: learnbyexample.net@gmail.com
4746

4847
Twitter: https://twitter.com/learn_byexample
@@ -63,7 +62,8 @@ Resources mentioned in Acknowledgements section above are available under origin
6362

6463
## Book version
6564

66-
3.1
65+
3.2
66+
6767
See [Version_changes.md](https://github.com/learnbyexample/py_regular_expressions/blob/master/Version_changes.md) to track changes across book versions.
6868

6969
# Why is it needed?
@@ -2322,8 +2322,8 @@ This chapter introduced different ways to work with various matching portions of
23222322
**n)** Convert the comma separated strings to corresponding `dict` objects as shown below.
23232323

23242324
```ruby
2325-
>>> row1 = 'name:rohan,maths:75,phy:89'
2326-
>>> row2 = 'name:rose,maths:88,phy:92'
2325+
>>> row1 = 'name:rohan,maths:75,phy:89,'
2326+
>>> row2 = 'name:rose,maths:88,phy:92,'
23272327

23282328
>>> pat = re.compile() ##### add your solution here
23292329

@@ -2831,7 +2831,7 @@ Here's some examples for using backreferences within **RE definition**. Only `\N
28312831
'aa a 42 f_1 f_13.14'
28322832
```
28332833

2834-
>![info](images/info.svg) Since `\g<N>` syntax is not available in RE definition, use octal escapes to avoid ambiguity between normal digit characters and backreferences.
2834+
>![info](images/info.svg) Since `\g<N>` syntax is not available in RE definition, use formats like hexadecimal escapes to avoid ambiguity between normal digit characters and backreferences.
28352835
28362836
```ruby
28372837
>>> s = 'abcdefghijklmna1d'
@@ -2852,7 +2852,7 @@ re.error: invalid group reference 11 at position 6
28522852
'Xd'
28532853
```
28542854

2855-
>![warning](images/warning.svg) It may be obvious, but it should be noted that backreference will provide the string that was matched, not the RE that was inside the capture group. For example, if `([0-9][a-f])` matches `3b`, then backreferencing will give `3b` and not any other valid match of RE like `8f`, `0a` etc. This is akin to how variables behave in programming, only the result of expression stays after variable assignment, not the expression itself. `regex` module supports [Subexpression calls](#subexpression-calls) to refer to the RE itself.
2855+
>![warning](images/warning.svg) It may be obvious, but it should be noted that backreference will provide the string that was matched, not the RE that was inside the capture group. For example, if `(\d[a-f])` matches `3b`, then backreferencing will give `3b` and not any other valid match of RE like `8f`, `0a` etc. This is akin to how variables behave in programming, only the result of expression stays after variable assignment, not the expression itself. `regex` module supports [Subexpression calls](#subexpression-calls) to refer to the RE itself.
28562856
28572857
## Non-capturing groups
28582858

@@ -3028,7 +3028,7 @@ The `expand` method on `re.Match` objects accepts syntax similar to the replacem
30283028
| | `0円` and `\NNN` will be treated as octal escapes |
30293029
| `\g<N>` | backreference, gives matched portion of Nth capture group |
30303030
| | applies only to replacement section |
3031-
| | use octal escapes to prevent ambiguity in RE definition |
3031+
| | use escapes to prevent ambiguity in RE definition |
30323032
| | possible values: `\g<0>`, `\g<1>`, etc (not limited to 99) |
30333033
| | `\g<0>` refers to entire matched portion |
30343034
| `(?:pat)` | non-capturing group |
@@ -3900,7 +3900,7 @@ This chapter showed some of the flags that can be used to change default behavio
39003900

39013901
## Exercises
39023902

3903-
**a)** Remove from first occurrence of `hat` to last occurrence of `ice` for the given input strings. Match these markers case insensitively.
3903+
**a)** Remove from first occurrence of `hat` to last occurrence of `it` for the given input strings. Match these markers case insensitively.
39043904

39053905
```ruby
39063906
>>> s1 = 'But Cool THAT\nsee What okay\nwow quite'
@@ -4109,7 +4109,7 @@ False
41094109

41104110
# regex module
41114111

4112-
The third party `regex` module (https://pypi.org/project/regex/) offers advanced features like those found in Perl language and other regular expression implementations. To install the module from command line, you can use either of these depending on your usage:
4112+
The third party `regex` module ([https://pypi.org/project/regex/](https://pypi.org/project/regex/)) offers advanced features like those found in Perl language and other regular expression implementations. To install the module from command line, you can use either of these depending on your usage:
41134113

41144114
* `pip install regex` in a virtual environment
41154115
* `python3.8 -m pip install --user regex` for system wide accessibility
126 Bytes
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /