DEV Community

Discussion on: What are the least intuitive fundamentals and best practices in software development?

Collapse
 
ben profile image
Ben Halpern

I’ve gotta go with regex. I didn’t ever really get “taught” regex, and Googling to find that the answer to my problem was a bunch of gobbledygook was a trip.

Collapse
 
matthewbdaly profile image
Matthew Daly

I learned regexes by learning Perl in 2010. Ever since then my once-fearsome regex skills have atrophied to the point that I now struggle to write one.

Collapse
 
databasesponge profile image
MetaDave 🇪🇺

I'm going to guess that you have rubular.com bookmarked.

Collapse
 
briwa profile image
briwa

regexr.com is better, IMO. And it's open source! github.com/gskinner/regexr/

Thread Thread
 
johannesvollmer profile image
Johannes Vollmer

I just wrote a node-based regex editor:

GitHub logo johannesvollmer / regex-nodes

Visualize and edit regular expressions for use in javascript

Regex Nodes

This node-based regular expression editor helps you understand and edit regular expressions for use in your Javascript code.

If your regular expressions are complex enough to give this editor relevance you probably should consider not using regular expressions, haha.

Why Nodes?

One of the problems with regular expressions is that they get quite messy very quickly. Operator precedence is not always obvious and can be misleading Nodes, on the other hand, are a visual hierarchy. A text-based regex cannot simply be broken into several lines or indented because that would alter the meaning of the expression.

The other major benefit of nodes is that the editor will prevent you from producing invalid expressions. Other regex editors analyze the possibly incorrect regular expression that the user has come up with. The node editor will allow you to enter your intention and generate a correct regular expression.

In addition, nodes…

If you have some spare time, let me know what you think of it!

Collapse
 
tommym9 profile image
Tom Metcalfe

I've been cheating for years using: regex101.com/

Best thing is it explains what each bit is doing so I can learn as I go along.

Collapse
 
cjbrooks12 profile image
Casey Brooks

The funny thing is, I've found it's sometimes far easier and cleaner to just write a full parser than a really complicated regex. A pretty decent recursive descent parser only takes a few dozen lines of code, and you get full recursive structures and an AST, which are a whole lot easier to work with than complex capturing groups.

Regex is a very useful tool, but don't let that be the only tool in your arsenal for String processing.

Collapse
 
dark_james profile image
James

Agreed, especially since very few examples break them up into manageable bites and instead present you with strings for Cthulhu

Collapse
 
gksander profile image
Grant Sander

I agree. I avoided RegEx's for a couple years. One morning I sat down with a cup of coffee and forced myself to thoroughly read through this chapter (great book in general). Now I'm using RegEx on a daily basis and loving it. I really liked the diagrams in the Eloquent chapter, helped me make sense of the gobbledygook.

I mostly write JavaScript, but that chapter also helped me a lot with writing Nginx/Apache proxies and rewrites. Now I'm not doing Google-guess-and-check when writing proxies in Nginx 😆.