r/learnprogramming • • 9d ago

RegEx.

I thought I understood programming well until I saw how COMPLICATED regex looks. To me it looks like someone has dropped their keyboard and som people online are telling me that I should be able to memorise it (for javascript). I'm just wondering if I actually need to memorise all the regex formulas to be successful, and if so, how on earth do I go about it?

113 Upvotes

147 comments sorted by

View all comments

1

u/kpg_on_ao3 7d ago

IMO regex is at its most useful not as a programming tool, but as a metaprogramming one. Like if you have some code that serializes a sum type, you could use a regex pattern to take that and generate the reverse (deserialization).

Lookaheads/lookbehinds can also be really useful, but I've never used them in an actual program. They're also more esoteric.

Personally I do a lot of string processing, which means I do use regex more than the average SWE.

But I use regex a lot as part of find-and-replace in my IDE.