Jump to ratings and reviews
Rate this book

Mastering Python Regular Expressions

Rate this book
Leverage regular expressions in Python even for the most complex featuresAbout This BookExplore the workings of Regular Expressions in PythonLearn all about optimizing regular expressions using RegexBuddyFull of practical and step-by-step examples, tips for performance, and solutions for performance-related problems faced by users all over the worldWho This Book Is ForThis book is aimed at Python developers who want to learn how to leverage Regular Expressions in Python. Basic knowledge of Python is required for a better understanding.

What You Will LearnExplore the regular expressions syntaxImprove the readability and future maintenance of the regexFind solutions for typical problems with regular expressionsFamiliarize yourself with match and search operationsLeverage the look around technique to create powerful regular expressionsGain insight on the uses of GroupsGet to know how the regex engine works through the Backtracking processEnhance the performance of your regular expressionsIn DetailRegular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. They are considered the Swiss army knife of text processing. Powerful search, replacement, extraction and validation of strings, repetitive and complex tasks are reduced to a simple pattern using regular expressions.

Mastering Python Regular Expressions will teach you about Regular Expressions, starting from the basics, irrespective of the language being used, and then it will show you how to use them in Python. You will learn the finer details of what Python supports and how to do it, and the differences between Python 2.x and Python 3.x.

The book starts with a general review of the theory behind the regular expressions to follow with an overview of the Python regex module implementation, and then moves on to advanced topics like grouping, looking around, and performance.

You will explore how to leverage Regular Expressions in Python, some advanced aspects of Regular Expressions and also how to measure and improve their performance. You will get a better understanding of the working of alternators and quantifiers. Also, you will comprehend the importance of grouping before finally moving on to performance optimization techniques like the RegexBuddy Tool and Backtracking.

Mastering Python Regular Expressions provides all the information essential for a better understanding of Regular Expressions in Python.

168 pages, Kindle Edition

First published January 1, 2014

22 people are currently reading
52 people want to read

About the author

Félix López

2 books16 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
16 (28%)
4 stars
22 (39%)
3 stars
13 (23%)
2 stars
3 (5%)
1 star
2 (3%)
Displaying 1 - 19 of 19 reviews
Profile Image for Arash Amani.
51 reviews8 followers
Read
January 9, 2017
it was useful and it help me to understand regular expression. I want to read this book again :)
Profile Image for Christopher.
1,409 reviews213 followers
March 22, 2016
Mastering Python Regular Expression has a promising title, and I certainly wanted to bring my Python RE skills to true mastery, but I was sorely disappointed by this book. It consists of little more than the authors’ rephrasing of the official Python API documentation. Regular expressions are notoriously complex and require loads of examples and try-it-yourself assignments to get down, but this book only presents each aspect of REs in an extremely concise and deathly boring fashion before moving on. Before you know it, the book has finished (it is only 110 pages!), and you'll hardly be any more comfortable with regex than when you started.

The book definitely has a dodgy air about it. The last part of the book is essentially an advertisement for the commercial software RegexBuddy. I’ll be sure to avoid any offerings from Packt Publishing in the future. As an example of just how little effort was put into this book from the publisher's part, the non-native English of the two Spanish-speaking authors was never polished by an editor. Consequently, the book reads as very unprofessional, sometimes even annoying, e.g. “The IEEE thought their POSIX standard has tried to standardize and give better Unicode support to the regular expression syntax and behaviors. This is called the POSIX flavor of the regular expressions.”

As a general introduction to regular expressions, you would be much better off with O’Reilly's Mastering Regular Expressions (though it uses Perl for teaching, the particular regular-expression dialect it uses is very similar to Python's own). When it comes to exploiting REs in Python, pretty much any API documentation or online tutorial will be just as good, if not much better, than this book.
Profile Image for Olha.
96 reviews10 followers
Read
May 8, 2018
This book is at least useful: with about 20 pages of it I was able to accomplish my task (to replace a project url in .git/config files ).
But I found much more efficient way to learn regexps: practice on HackerRank.
So put the book away and solve tutorial-organized challenges.
Profile Image for Alaa Nour.
1 review1 follower
Read
October 17, 2016
Short but very useful book , I know than i did before it
Profile Image for Andreas Kontokanis.
16 reviews3 followers
May 3, 2019
It is clear a misleading title for this kind of book. It is almost a pocket reference guide with very little examples. I don't believe I mastered anything by reading this book. I only had a glimpse of what I can do with python and RegEx. It would be nicer to have a title like "Presenting Regex with Python".
Surely there are much better ways to learn RegEx and this book doesn't add anything more than Python some websites together.
RegEx can be a very difficult subject to master and you need more examples and try and error examples to master it.
I finished the book and I am not sure that I learned more than a cheatsheet in python could give me.
Profile Image for Xianshun Chen.
88 reviews2 followers
November 3, 2020
The book seems to be basic and lack of practical examples, but i was able to use to revise a few concepts such as

named pattern:

Example:

match = re.search(r'(?P\s*oz', 'Vol: 100 OZ', flags=re.IGNORECASE)
print(match.group('ounce_val'))


sub with named pattern

Example:
print(re.sub(r'(?P\s*oz', 'This item is \g ounce', 'Vol: 100 OZ'))


non-named group ?: (i started to read this book cos i forgot this pattern)


144 reviews5 followers
January 19, 2024
A succinct, but useful reference to using regular expressions in Python. It makes a good second book on the topic of regular expressions, or a good first book if you generally are familiar but need to learn the python dialect.

Despite being from 2014, the only really dated portion of the book is the Python 2.x references. The book covers Python 3 well, and the Python 3 aspects haven't changed much since then.
Profile Image for Hibiscus.
337 reviews
January 19, 2023
This was an easy read. There was nothing new here after I had read the RegexBuddy tutorials.
No recursion, no subroutines, no atomic groups, no possessive quantifiers.
The most advanced it got was the short overview of look-around assertions.
Profile Image for Utsav Parashar.
40 reviews7 followers
January 28, 2019
Nice book, with all about regex in python.
After reading first two chapters one can write useful regex in python.
Profile Image for Jin Shusong.
78 reviews1 follower
March 26, 2019
I think this book is excellent for a beginner to understand regular expressions.
Profile Image for Hadiana Sliwa.
67 reviews8 followers
June 8, 2021
Very short, I recommend it to someone that wants an overview on RE, otherwise for someone that wants to master RE it won't be helpful.
Profile Image for Monqeth.
319 reviews114 followers
May 26, 2023
هل لاحظت عندما تسجل في موقع ويطلب منك إدخال إيميل أو هاتف أو صندوق بريد صحيح ويمنعك من إدخال أي حاجة بالباتنجان؟ كل ذلك يتم في المتصفح نفسه قبل إرسال البيانات إلى الخادم. يتم عبر استخدام تقنية برمجية اسمها Regular Expressions
لكن التقنية يمكن استخدامها لتحليل الملفات النصية العادية وليست محصورة في المواقع، كما كانت بدايتها في نظام لينوكس الذي يستخدم سطر الأوامر.

ريغولار إكسبريشنز موجودة في معظم لغات البرمجة، وتقوم بتحليل النصوص عبر كتابة كود بسيط قد يصبح معقدًا كلما كان معيار التحليل أكثر دقة.
الجميل في ريغولار إكسبريشنز أنها مستقلة بذاتها، تستطيع إرسال الكود إلى صديقك حتى لو كان يستخدم لغة برمجة مختلفة.

في هذا الكتاب نتعلم تلك التقنية وكيفية كتابتها في لغة بايثون، فلابد من مقدمة في بايثون وأنصح بالقسم الأول من كتاب Python Crash Course by Eric Matthes

كتابنا جيد جدًا في الشرح لكن أمثلة الكتاب التالي أكثر واقعية.
Python 3 Standard Library by Example


استخدم في البرمجة برنامجا شهيرًا يحتوي على متجر مجاني للإضافات والثيمات واسمه VSCode


Profile Image for Pavel Karateev.
18 reviews5 followers
December 8, 2015
Simply an excellent Python regex book. Short and sharp. Read it if you need to become familiar with the topic asap. I recommend to use IPython notebook for book examples, that way you will gain motor memory and create a personal "HowTo" manual.
230 reviews3 followers
September 17, 2015
It is short, but very useful book on regular expressions in Python. I found the chapter on performance and optimization helpful.
Displaying 1 - 19 of 19 reviews

Can't find what you're looking for?

Get help and learn more about the design.