6

What are some Regular Expression concepts you find hard to grok?

 2 years ago
source link: https://dev.to/nickytonline/what-are-some-regular-expression-concepts-you-find-hard-to-grok-402n
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for What are some Regular Expression concepts you find hard to grok?
Nick Taylor

Posted on Jul 3

What are some Regular Expression concepts you find hard to grok?

I was reading a Tweet from my friend Amy on Twitter where they put out a Twitter poll that is currently going on.

🐾 Amy Shackles 🐾 profile image
🐾 Amy Shackles 🐾
twitter logo
What emotional reaction do you have toward regular expressions (regex)?
14:49 PM - 03 Jul 2022

to which I replied in my funny way.

Nick Taylor profile image
Nick Taylor
twitter logo
@AmyShackles /(?<reaction>Fear|Anger|Disgust|Excitement)/i
15:14 PM - 03 Jul 2022

And this got me to thinking that many folks struggle with regular expressions. What are some things that trip you up when it comes to regular expressions?

Discussion (9)

pic

CollapseExpand

I said this on Twitter but for me the thing that trips me up is constantly having to translate in my head between the thing I want to do in a regular expression and the specific regex syntax I need to accomplish it. The regex mental model is actually quite simple but the syntax is a nightmare.

Comment button Reply

CollapseExpand

The book Mastering Regular Expressions: Powerful Techniques for Perl and Other Tools by Jeffrey E.F. Friedl really helped me grok regular expressions. Excellent book.

Language agnostic, really; it's about the regex concepts.

Comment button Reply

CollapseExpand

Author

Jul 4

Yeah, I have that book. It's really great!

Comment button Reply

CollapseExpand

Greedy / non-greedy lookback / forward.

Standard pattern matching I'm pretty good at now with regex but capture groups combined with multiple captures and the greedy stuff is a little crazy still.

I found using regexr.com really helpful as you can visualise quickly what's going on

Comment button Reply

CollapseExpandCollapseExpand

This is the most useful thing I ever downloaded:

Regex cheatsheet

Comment button Reply

CollapseExpand

It's when it gets -- 'nested' I guess? But when there need to be multiple matches for several pieces of the pattern and that gets reflected in the syntax, I start to get confused.

Comment button Reply

CollapseExpand

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK