Portrait of Michael Limberger

Michael Limberger

Need me? Email mike@limberger.ca

Regex

Advanced Regular Expressions

Poetry, not alphabet

This talk is the deeper PCRE night. Lookaheads, named groups, and patterns that look like noise until you walk them slowly.

Tonight we learn to write poetry.

PCRE is Perl Compatible Regular Expressions, the extended regex syntax Perl invented decades ago and the rest of the world borrowed. When you run grep -P on Linux, you are using PCRE. Python, PHP, Ruby, Java, JavaScript, Rust, and Go all took from it. Some implement more than others. The core ideas travel. Learn this once and it works in every language you touch.

The walk tonight

Five rooms, then AI. We go from functional to surgical, in this order.

Quantifiers. You know greedy and non-greedy exist. Tonight you see why they behave that way, and you meet possessive quantifiers, which most people never learn.

Capture groups, the full picture. Named groups, backreferences inside the pattern (not only in replacements), nested numbering, and when to use what.

Regex subroutines. Define a pattern once, call it again. DRY, Don't Repeat Yourself, applied to regex. This is the feature that makes people say regex can do that.

Lookaround. Match based on what comes before or after your target without including it in the match. That changes everything.

The modifier toolkit. You know /g and /i. There are more, and some of them are genuinely useful.

Then we tie regex into AI workflows: clean data before it hits a model, use a model to help write and debug a pattern. The practical intersection.

What you need

Same kit as last time. A terminal. Some text files to practice on. Everything from Regex Therapy, because we build on that floor. If you missed the first session you can still follow along. Some basics will move fast.

We will use grep -P for most demos because it gives full PCRE in the terminal. If you are on a Mac and grep -P does not work, use Perl directly.

Show me

perl -ne 'print if /your_pattern/' filename

Perl is PCRE's home turf. That one-liner does the same job as grep -P. Everything works.

For search and replace, the other one-liner:

Show me

perl -pe 's/pattern/replacement/flags' filename
+----------------------------------------------------------+
|  PCRE is the lingua franca of pattern matching.          |
|  Master it once. Use it everywhere. Forever.             |
+----------------------------------------------------------+

Let's get into it.