r/learnpython • u/ASIC_SP learnbyexample • Jul 07 '20
My Python regex ebook with hundreds of examples and exercises is currently free
Posting with mod's permission.
Hello!
I recently updated my Python re(gex)? ebook. I had first released it at the beginning of last year (https://www.reddit.com/r/learnpython/comments/aevgbi/i_wrote_a_book_on_python_regular_expressions_it/).
My initial motivation was to add epub format and separate out third-party regex module content into a separate chapter. An email exchange with a reader, a look at feedback from the past year and my own improvements as a writer resulted in a significant overhaul. It took me about 6 weeks to complete the revision instead of 1-2 weeks that I estimated. Sounds familiar right? I’m definitely pleased with the changes, but along the way I added a long list of TODOs that will probably need months of work. Future me is not going to be pleased.
To get pdf/epub versions, use any of these links:
As a bundle (Python/Ruby/JS regex and grep/sed/awk cli tools):
I made all my books free at the end of March when the pandemic hit my country. The virus doesn’t seem to be going away anytime soon, so I’ll probably start charging again after I finish updating the Ruby and JS regex books, which will take me at least till end of July. You can still pay if you wish.
You can read the entire book from the GitHub repo - https://github.com/learnbyexample/py_regular_expressions. The repo also contains the code snippets used in the book and a handy way to access all the exercises in a single file. You can also find the solutions there.
I’d highly appreciate your feedback. That’s been a major motivating factor to keep writing as well as for improving the content.
Happy learning :)
3
3
3
u/skellious Jul 07 '20
Awesome, thank you. When I've made some use of them I'll come back and send you money :)
2
u/ASIC_SP learnbyexample Jul 08 '20
You're welcome, happy learning :)
I'd appreciate feedback more than money, so if you do get some time to read the book, do let me know how you found it :)
2
2
2
2
2
2
2
u/zeus5552 Jul 08 '20
.
2
u/ASIC_SP learnbyexample Jul 08 '20
did you accidentally overwrite the comment, I'm seeing only
.character2
u/zeus5552 Jul 08 '20
I was having internet problems while downloading the book on phone. So the . is like a watch later. The table of contents look great btw.
2
u/ASIC_SP learnbyexample Jul 08 '20
Oh ok :)
Thanks for checking out the book and feedback about contents, happy learning :)
2
2
u/GaminB4 Jul 08 '20
noob question, what are these regular expressions?
2
u/ASIC_SP learnbyexample Jul 08 '20
From https://en.wikipedia.org/wiki/Regular_expression
A regular expression (shortened as regex or regexp;[1] also referred to as rational expression)[2][3] is a sequence of characters that define a search pattern. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.
reandregexare modules that help you with a wide variety of text processing needs. Here's some examples:# split based on one or more digit characters >>> re.split(r'\d+', 'Sample123string42with777numbers') ['Sample', 'string', 'with', 'numbers'] # swap words that are separated by a comma >>> re.sub(r'(\w+),(\w+)', r'\2,\1', 'good,bad 42,24') 'bad,good 24,42' # match if 'go' is not there between 'at' and 'par' >>> bool(re.search(r'at((?!go).)*par', 'fox,cat,dog,parrot')) True
0
0
39
Jul 07 '20
[removed] — view removed comment
7
u/ASIC_SP learnbyexample Jul 08 '20
finally inspired me to look into Markdown
Yeah, markdown is increasingly becoming common.. it is used in reddit/hn/lobsters/stackoverflow/slack/github/gitlab/note-taking-apps etc. If you are interested in generating ebooks from markdown, I have a post for that (https://learnbyexample.github.io/tutorial/ebook-generation/customizing-pandoc/) - though I need to update it.
One suggestion would be to tie the books to a website, (preferably yours) where someone could directly test and implement your regex examples
My initial plan was to create a GUI app in Python to provide interactive course. I haven't started it at all. Video course, again not started yet. I recently came across sites that can help with creating text-based interactive course with development enviroment baked in the website itself. I'm currently leaning towards this because they also would do the marketing stuff and provide initial review before publishing.
Also, github is sort of a place for people who already know some of this stuff, I skimmed the first few pages of text and it seems you are writing towards a more advanced user. If that is your intent then that is great.
I'm using GitHub to provide the markdown source of the book and an easy access to code snippets, exercises, etc. My intention is to cater to primarily beginners to regex, provided they are already familiar with Python syntax and programming basics. Another comment suggested that I improve the introduction chapter to show what regex can do and summarize the book. Hopefully, that'll make it more accessible to beginners.
Thanks a lot for the feedback and ideas. I'll take some time to reflect and make changes accordingly.
3
1
Jul 07 '20
[removed] — view removed comment
2
u/ASIC_SP learnbyexample Jul 08 '20
Thanks for the feedback. I'll make some changes based on yours and the other comments. I certainly wish to convey that the book is for beginners to regex as well, provided they are comfortable with Python before starting my book.
2
Jul 08 '20
[removed] — view removed comment
2
u/ASIC_SP learnbyexample Jul 08 '20
Oh ok, I misunderstood your comment.
I highly doubt majority of intermediate to advanced users are going to navigate to your site to try examples anyhow. Most would likely see an application from the get go.
Yeah, the other feedbacks also emphasized that showing what kind of things regex can do in the introduction chapter would be better. As well as to summarize what I'll be covering the book.
10
u/DrBobHope Jul 07 '20
Took a quick glance through it, and I'd argue its actually just the right level of depth for beginner users, and the more adept user. It has all the basics, and later on, goes into some of the more advanced/extensive uses you can have with regex (and additional reading for anyone who wants more advanced uses).
However, there isn't quite an introduction. The book is partitioned less like a book, and more like documentation (i.e. here is first regex function, lets break down this function, then next function, etc.). If people are looking at this with no knowledge of regex, they are immediately thrown into a rabbit hole of different uses of regex, without understanding why they'd need it in the first place or what it can do.
I'd recommend adding a brief introduction, i.e. regex is this, and it can do something like this. If you take: https://www.w3schools.com/python/python_regex.asp as an example, right off the bat you can see a very simple straightforward breakdown, and some very basic demonstrations of regex right off the bat (without going into any detail,ignore their table). Thus, now the user knows at least what regex can do, and they will read further if they wish to use the tool.
To add on to the introduction, I believe most people just don't know what regex is capable of. And again since your book is formatted similar to a doc, I still wouldn't get to know what regex can do, without reading at least 20+ pages. I think it'd be nice to have a section (could be the intro) that actually goes through 1 simple example that summerizes the idea of each section in your book (again like the above link, search, find, split, etc.), and maybe a hyperlink that jumps to that section. But this is just a personal preference, I'd like to see what the book can offer right off the bat, otherwise I probably won't go too into it. And, it'll be easy for me to look back if I ever forget (I forgot what re.search does, right in the intro there is a hyperlink I can click to jump to it0.
Regardless, I think it's great, and I've personally bookmarked it. Thank you!