How to get good at writing regular expressions

How to get good at writing regular expressions
0

I’ve been doing the FCC Regex tutorial, but when every now and then I come across a checkpoint, tutorial test checks, that I can quite complete. E.g.: I managed to get all the checks on the simple password checker except one. I tried all sorts of things and as a last resort, I read the hints and tried to right an regex based on that but was still coming up short so even though I didn’t want to, I had to look at the solution.
How do I get good at writing regex?
How should I go about learning them?
(Aside: I like writing code (HTML, CSS, JS) so I want to get hired at least as a front-end web developer as soon as possible and I feel like since I’m not super great at writing regex that I’m not going to get hired. I really could use some work right now.)
Any advice is welcome.

Regular expressions are powerful tools and do get used fairly often, but most of the time they aren’t horribly complex. Don’t expect to tested on them in-depth. Many developers pull a face when you bring up regular expressions. (I rather like them though.) You learn them through practice and repeated exposure.

2 Likes

Practice. If you’re on a unixoid OS, I suggest getting to know grep (or better yet, ag from the silver_searcher package). If not, I suggest installing linux in a VM and playing with it. That’s how most regex experts pick it up.

Front-end developers don’t really use regexes that often. If you find yourself having to scrape your own page with regexes, you’re probably doing it wrong.

1 Like

I use regular expressions a decent amount in front end stuff. I’ve used it with very data-heavy UIs that need to sort, filter, manipulate text-based data. I also work on a UI that has a lot of user input fields that we need to validate. I’m very rarely having to do extremely complex patterns these days, but I need to be comfortable with them.

Where you can really have fun with regular expressions is the good old “spend a day writing a script to automate something that would take you 4 hours to do by hand” use case. :smiley:

1 Like

I was thinking largely of page visuals, navigation and so forth, but you’re right: as a lot of formerly backend stuff moves to the front end, the line is getting a lot blurrier.

1 Like

It’s a brave new world wide web.

I’m sorry. That was terrible. I’m terrible.

Beats “Web 3.0” though. Or is it 4.0 now? I’m always a few steps behind the latest lingo the kids are using.

1 Like

Thank you for the encouraging words.

I don’t know what grep, ag, silver_searcher are. But I may look up more about them after I finish the FCC tutorials I’m on. I have a HP computer with windows… I don’t have the money to afford to purchase anything.

Could you give me an example of such a script, automation script?

Thank y’all for your input. :slightly_smiling_face:

Linux and the VM software are free, though if you have no practical use for Linux, I suppose it’s pointless to recommend installing it. You can pick up grep (and probably ag) for Windows besides. Your editor/IDE (like VSCode or WebStorm or whatever) probably has a regex search and regex replace too, which will actually come in handy.

The larger point remains: practice, practice, practice.