You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[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
77
75
*[stackoverflow](https://stackoverflow.com/) — for getting answers to pertinent questions on Python and regular expressions
78
76
*[tex.stackexchange](https://tex.stackexchange.com/) — for help on `pandoc` and `tex` related questions
79
77
* 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)
80
78
*[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
81
80
*[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
83
82
***Hugh**'s email exchanges helped me significantly to improve the presentation of concepts and exercises
84
83
*[Christopher Patti](https://github.com/feoh) for reviewing the book, providing feedback and brightening the day with kind words
85
84
* 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/)
Copy file name to clipboardExpand all lines: py_regex.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,19 @@ If you have prior experience with a programming language, but new to Python, see
16
16
* 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.
17
17
* Unless otherwise noted, all examples and explanations are meant for **ASCII** characters.
18
18
* 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.
20
20
21
21
## Acknowledgements
22
22
23
23
*[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
25
25
*[stackoverflow](https://stackoverflow.com/) — for getting answers to pertinent questions on Python and regular expressions
26
26
*[tex.stackexchange](https://tex.stackexchange.com/) — for help on `pandoc` and `tex` related questions
27
27
* 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)
28
28
*[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
29
30
*[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
31
32
***Hugh**'s email exchanges helped me significantly to improve the presentation of concepts and exercises
32
33
*[Christopher Patti](https://github.com/feoh) for reviewing the book, providing feedback and brightening the day with kind words
33
34
* 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
@@ -63,7 +62,8 @@ Resources mentioned in Acknowledgements section above are available under origin
63
62
64
63
## Book version
65
64
66
-
3.1
65
+
3.2
66
+
67
67
See [Version_changes.md](https://github.com/learnbyexample/py_regular_expressions/blob/master/Version_changes.md) to track changes across book versions.
68
68
69
69
# Why is it needed?
@@ -2322,8 +2322,8 @@ This chapter introduced different ways to work with various matching portions of
2322
2322
**n)** Convert the comma separated strings to corresponding `dict` objects as shown below.
2323
2323
2324
2324
```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,'
2327
2327
2328
2328
>>> pat = re.compile() ##### add your solution here
2329
2329
@@ -2831,7 +2831,7 @@ Here's some examples for using backreferences within **RE definition**. Only `\N
2831
2831
'aa a 42 f_1 f_13.14'
2832
2832
```
2833
2833
2834
-
> Since `\g<N>` syntax is not available in RE definition, use octal escapes to avoid ambiguity between normal digit characters and backreferences.
2834
+
> Since `\g<N>` syntax is not available in RE definition, use formats like hexadecimal escapes to avoid ambiguity between normal digit characters and backreferences.
2835
2835
2836
2836
```ruby
2837
2837
>>> s ='abcdefghijklmna1d'
@@ -2852,7 +2852,7 @@ re.error: invalid group reference 11 at position 6
2852
2852
'Xd'
2853
2853
```
2854
2854
2855
-
> 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
+
> 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.
2856
2856
2857
2857
## Non-capturing groups
2858
2858
@@ -3028,7 +3028,7 @@ The `expand` method on `re.Match` objects accepts syntax similar to the replacem
3028
3028
||`0円` and `\NNN` will be treated as octal escapes |
3029
3029
|`\g<N>`| backreference, gives matched portion of Nth capture group |
3030
3030
|| applies only to replacement section |
3031
-
|| use octal escapes to prevent ambiguity in RE definition |
3031
+
|| use escapes to prevent ambiguity in RE definition |
3032
3032
|| possible values: `\g<0>`, `\g<1>`, etc (not limited to 99) |
3033
3033
||`\g<0>` refers to entire matched portion |
3034
3034
|`(?:pat)`| non-capturing group |
@@ -3900,7 +3900,7 @@ This chapter showed some of the flags that can be used to change default behavio
3900
3900
3901
3901
## Exercises
3902
3902
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.
3904
3904
3905
3905
```ruby
3906
3906
>>> s1 ='But Cool THAT\nsee What okay\nwow quite'
@@ -4109,7 +4109,7 @@ False
4109
4109
4110
4110
# regex module
4111
4111
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:
4113
4113
4114
4114
*`pip install regex` in a virtual environment
4115
4115
*`python3.8 -m pip install --user regex` for system wide accessibility
0 commit comments