Regular Expressions vs. Regex: CS geekery

A few days ago in one of the online programming groups I'm in someone was asking for help with a regex. I recommended using a non-capturing group, since she had specific things she needed to return at the end. Usually when I use regexes I'm just checking for a match or not, so I've rarely bothered with capturing or not capturing, so I decided to read up a bit. Found this excellent resource, which I shall have to remember in future, and started browsing around it looking at the wealth of info on all aspects of regexes, when a thought occurred to me. Did we learn about this stuff in Automata, Languages, and Computability (AKA the mother of all theory classes in the CS masters degree, most of which I have forgotten)? Is that part of CS regular expressions, or strictly a programming language implementation regex thing? Where is the line for that, anyway?

I started Googling, and turned up several excellent answers on the CS Stack Exchange, which I really ought to browse more often as it has very interesting stuff. The most succinct is here
tl;dr backrefs.
As soon as there is a \1 (or any number that isn't used to escape unicode) in the regexp it is not a regular expression.
And there's also lots of great info here.

And that is my CS geekery of the day, which I wished to share with my fellow programming geeks. I've always had a love/hate relationship with regexes/regular expressions. The programming language implementation variety are very useful and powerful, of course, but they also massively reduce readability and I find they're way too often used as some sort of "Real Programmer" benchmark by obnoxious code bros. Then there's the whole connection to actual CS theory, with regular expressions being an important part of theoretical languages and automata, but the implementations of regexes in programming languages go way beyond that, so it's all weird and strange...

Also the person I was trying to help never replied to my suggestions and that is seriously one of my pet peeves. Did the advice help? Did you get it figured out? Don't leave me hanging! Sigh. 


Comments

Popular posts from this blog

"Does it get easier?" Yes, but Also No...

How to Land Your First Dev Job: Develop Yourself, Market Yourself

Git. The WHAT and WHY Edition.