DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on

How do you feel about regex?

Regex seems to have a broad array of love and hate. How do you feel about it? Do you seek to use or avoid it as a problem solver, and how much do you understand it?

Latest comments (65)

Collapse
 
lewiscowles1986 profile image
Lewis Cowles

It's generated code, according to a declarative syntax, that has been tested and iterated on by millions of projects over decades... What isn't to love?

Prefer if we can use simpler things, but if it's needed. Then it is needed.

Collapse
 
voyeg3r profile image
Sérgio Araújo

As a vim/nvim user I would say that regex is my bread and butter. I also love using GNU grep, "Global REgular exPression Print", sed and a bunch of other programs that make use of it.

Collapse
 
joaogouveia profile image
joao-gouveia

Regex is difficult to read and can have unanticipated side effects. I tend to run from it if I can.

Collapse
 
syxaxis profile image
George Johnson

Very useful BUT it's almost an entire language in it's own right. I kind of respect that and just skirt around it. I use online regex builders when I need a regex for a filter style func call and that's me and regex done with until next time!

There was an 300 page O'Reilly book sold at one point just on Regex and nothing else! That's how deep the rabbit hole goes on regex. If you can avoid regex, then do so, if you can't then make the expression simple and watertight by testing the heck out it. Regex is greedy and if you don't test it properly you will regret it later.

Collapse
 
michaelkith profile image
MICHAELKITH (GitHub username)

Hello Developers

Collapse
 
lepinekong profile image
lepinekong • Edited

In the past I hate them and just searched copy and paste because it was pretty simple need but as I'm currently developping a Visual Meta Programming tool I'm obliged to really understand what I'm doing like Lookaround and Lookbehind so I'm now starting to like them more :)

Collapse
 
zakwillis profile image
zakwillis

I think they are great. They don't work in all situations.

ultrapico.com/expresso.htm is for .Net and a great tool for creating regex expressions, it doesn't support all elements of regex. Am not a super genius on them but they are an essential element of development for me when handling information.

Here is an example of configuration from a translation file from my application which is an awesome DevOps Deployment application am hoping to market in future.

The configuration below is to either find a value or a regex expression in an input file (typically itself an application configuration file) to clean a development configuration file. Sounds complex, but a great way of translating source configuration into something generic for different environmental deployment.

Regexes provides more control, but aren't always the best approach.

inforhino.co.uk/beta/automation-an...

                        {"IsRegex": false, "FindValue" : "C:\\\\InfoRhino\\\\cms\\\\IRWebsite\\\\IRWebsiteCMS\\\\wwwroot\\\\ClientConfiguration\\\\TConfigType.json", "ReplacementValue" : "{TargetServerRoot}\\\\ClientConfiguration\\\\TConfigType.json"}
                        ,
                        {"IsRegex": false, "FindValue" : "C:\\\\InfoRhino\\\\cms\\\\Adverts", "ReplacementValue" : "{TargetServerRoot}\\\\Store\\\\Adverts"}
                        ,
                        {"IsRegex": false, "FindValue" : "C:\\\\InfoRhino\\\\cms\\\\IRWebsite\\\\IRWebsiteCMS\\\\wwwroot", "ReplacementValue" : "{TargetServerRoot}\\\\wwwroot"}
                        ,
                        {"IsRegex": false, "FindValue" : "content\\\\Cards", "ReplacementValue" : "Cards"}
                        ,
                        {"IsRegex": true, "FindValue" : "(?is-nx:(?<=\"CardDomainHeaderCaption\"\\:(\\s{0,1})\")([a-z0-9\\s\\,\\.]+))", "ReplacementValue" : "{CardDomainHeaderCaption}"}
                        ,
                        {"IsRegex": true, "FindValue" : "(?is-nx:(?<=\"CardDescription\"\\:(\\s{0,1})\")([a-z0-9\\s\\,\\.]+))", "ReplacementValue" : "{CardDescription}"}
                        ,                       
                        {"IsRegex": true, "FindValue" : "(?is-nx:(?<=\"CompanyName\"\\:(\\s{0,1})\")([a-z0-9\\s\\,\\.]+))", "ReplacementValue" : "{CompanyName}"}

Enter fullscreen mode Exit fullscreen mode
Collapse
 
davestewart profile image
Dave Stewart • Edited

regexone.com/ is BY FAR the best resource to learn RegEx from scratch.

Pretty much everything you would get in this book (but also worth reading!)
amazon.co.uk/Mastering-Regular-Exp...

And actually, core RegEx is fairly straightforward:

  • learn the tokens
  • read left to right
  • say what you see
  • (learn the tokens again)

Good luck!

Collapse
 
scorpit01 profile image
Anish Mahapatra

I'd rather master oop then master regex

Some comments may only be visible to logged-in visitors. Sign in to view all comments.