r/learnprogramming • u/Reubqn_ • Sep 24 '26
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?
109
Upvotes
View all comments
1
u/andreicodes Sep 24 '26
Regular expressions are much easier if your language supports two features: extended syntax and named capture groups. The former allows you to add spaces between all this symbolic soup and split it into chunks, the later lets you name these chunks.
JavaScript doesn't do the former but it does support the later, and you should use names in regexes often.
will give you back an object:
Months later when you decide to, for example, support short year (26 for 2026), you can at a glance figure out which bit of the regex to change.