
Regular Expression Puzzles and AI Coding Assistants
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Regular Expression Puzzles and AI Coding Assistants is the story of two competitors. On one side is David Mertz, an expert programmer and the author of the Web's most popular Regex tutorial. On the other are the AI powerhouse coding assistants, GitHub Copilot and OpenAI ChatGPT.
Here's how the contest works: David invents 24 Regex problems he calls puzzles and shows you how to tackle each one. When he's done, he has Copilot and ChatGPT work the same puzzles. What they produce intrigues him. Which side is likelier to get it right? Which will write simple and elegant code? Which makes smarter use of lesser known Regex library features? Read the book to find out.
David also offers AI best practices, showing how smart prompts return better results. By the end, you'll be a master at solving your own Regex puzzles, whether you use AI or not.
About the technology
Groundbreaking large language model research from OpenAI, Google, Amazon, and others have transformed expectations of machine-generated software. But how do these AI assistants, like ChatGPT and GitHub Copilot, measure up against regular expressions-a workhorse technology for developers used to describe, find, and manipulate patterns in text. Regular expressions are compact, complex, and subtle. Will AI assistants handle the challenge?
About the book
Regular Expression Puzzles and AI Coding Assistants is the perfect starting point for programmers of any experience level who want to understand the capabilities-and the limitations-of these exciting new tools. Author David Mertz presents 24 challenging regex puzzles, their traditional human-made solutions, and the fascinating answers given by popular AI assistants. Alongside these eye-opening puzzles you'll learn how to write prompts, integrate AI-generated coding suggestions, and interact with the assistant to get the results you want. By the end of the book, you'll have a clear understanding of where AI assistants can reliably write code for you and where you'll still need a human touch. Plus, you'll learn a lot about regular expressions!
About the reader
Code examples use simple Python and Regular Expressions. No experience with AI coding tools required.
About the author
David Mertz is the founder of KDM Training and an acclaimed contributor to the Python community. He is also the author of The Puzzling Quirks of Regular Expressions, Cleaning Data for Effective Data Science: Doing the Other 80% of the Work, and other books.
Table of Contents
1 The map and the territory
2 Quantifiers and special sub-patterns
3 Pitfalls and sand in the gears
4 Creating functions using regex
5 Easy, difficult, and impossible tasks
6 Conclusions
Appendix A: Learning to use regular expressions
More details
Other editions
Additional editions

Person
Content
- Intro
- inside front cover
- Regular Expression Puzzles and AI Coding Assistants
- Copyright
- contents
- front matter
- preface
- acknowledgments
- about this book
- Who should read this book
- Obtaining the tools used in this book
- Credits
- liveBook discussion forum
- about the author
- about the cover illustration
- 1 The map and the territory
- About regular expressions
- Rise of the programming machines
- Caveats
- Intentional software development
- As you read
- 2 Quantifiers and special sub-patterns
- Puzzle 1 Wildcard scope
- Author thoughts What will each pattern match?
- AI thoughts CodingNet
- Puzzle 2 Words and sequences
- Author thoughts Think about what defines word boundaries
- AI thoughts The transformator
- Puzzle 3 Endpoint classes
- Author thoughts Refine the regular expression to match what we want
- AI thoughts Are friends electric?
- Puzzle 4 A configuration format
- Author thoughts Remember that shapes have edges
- AI thoughts Notes from the Cyberdyne vault
- Puzzle 5 The Human Genome
- Author thoughts Remember the central dogma of molecular biology
- AI thoughts Do androids dream of electric sheep?
- 3 Pitfalls and sand in the gears
- Puzzle 6 Catastrophic backtracking
- Author thoughts Try hard to avoid catastrophes
- AI thoughts Technological singularity
- Puzzle 7 Playing dominoes
- Author thoughts Try to be more efficient than your first thought
- AI thoughts A war with sticks and stones
- Puzzle 8 Advanced dominoes
- Author thoughts Thoughts about digrams are always pleasant thoughts
- AI thoughts How many readers can pass the Turing Test?
- Puzzle 9 Sensor art
- Author thoughts Find a matching pattern, if possible
- AI thoughts My mind is going
- I can feel it
- 4 Creating functions using regexen
- Puzzle 10 Reimplementing str.count()
- Author thoughts How can a regex count the substring occurrences?
- AI thoughts Extraordinary machine
- Puzzle 11 Reimplementing str.count() (stricter)
- Author thoughts Write a Python function with the restrictions given
- AI thoughts The Horars of War
- Puzzle 12 Finding a name for a function
- Author thoughts Code is read far more often than it is written
- AI thoughts There are two hard problems in computer science
- Puzzle 13 Playing poker (Part 1)
- Author thoughts Functions are a big help in larger programs
- AI thoughts He can't read my poker face
- Puzzle 14 Playing poker (Part 2)
- Author thoughts Large buildings are built from small bricks
- AI thoughts The society for preventing cruelty to humans
- Puzzle 15 Playing poker (Part 3)
- Author thoughts You better cheat, cheat, if you can't win
- AI thoughts Someday machines will learn to count
- Puzzle 16 Playing poker (Part 4)
- Author thoughts You might risk identifying the "dead man's hand"
- AI thoughts Free will is not free
- Puzzle 17 Playing poker (Part 5)
- Author thoughts Remember that three is more than two, but less than four
- AI thoughts Counting to two
- 5 Easy, difficult, and impossible tasks
- Puzzle 18 Identifying equal counts
- Author thoughts Lateral thinking might help you find the answer
- AI thoughts Hic sunt dracones
- Puzzle 19 Matching before duplicate words
- Author thoughts Find a pattern that will fulfill the requirement
- AI thoughts Deep fakes in the Chomsky hierarchy
- Puzzle 20 Testing an IPv4 address
- Author thoughts Ask whether regexen are powerful enough for a problem
- AI thoughts I want to be a machine
- Puzzle 21 Matching a numeric sequence
- Author thoughts Rule out the impossible to be left with the solution
- AI thoughts Wheat and chessboards
- Puzzle 22 Matching the Fibonacci sequence
- Author thoughts The Golden Spiral beautifully generalizes Fibonacci numbers
- AI thoughts The fractal geometry of nature
- Puzzle 23 Matching the prime numbers
- Author thoughts Honor the fundamental theorem of arithmetic
- AI thoughts Sense and nonsense
- Puzzle 24 Matching relative prime numbers
- Author thoughts Nothing is either true or false but thinking makes it so
- AI thoughts Six impossible things before breakfast
- 6 Conclusions
- Appendix. Learning to use regular expressions
- What tools use regular expressions?
- Matching patterns in text: The basics
- Character literals
- Escaped characters literals
- Positional special characters
- The "wildcard" character
- Grouping regular expressions
- Using groups for backreferences
- Character classes
- Complement operator
- Alternation of patterns
- The basic abstract quantifier
- Matching patterns in text: Intermediate
- More abstract quantifiers
- Numeric quantifiers
- Backreferences
- Do not match more than you want to
- Tricks for restraining matches
- Tricks for restraining matches better
- Comments on modification tools
- A note on modification examples
- A literal-string modification example
- A pattern-match modification example
- Modification using backreferences
- Another warning on mismatching
- Advanced regular expression extensions
- About advanced features
- Non-greedy quantifiers
- Atomic grouping and possessive quantifiers
- Pattern-match modifiers
- Changing backreference behavior
- Naming backreferences
- Lookahead assertions
- Lookbehind assertions
- Making regular expressions more readable
- index
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.