Javascript algorithms that involve regex

Recently I am studying some algorithms just in case that when getting interviewed, I am gonna have to solve some algorithms in front of other people.

My question is : do I have to memorize all the different REGEX combo? Will this be tested?
Cos in my point of view, I think the interviewer should provide the REGEX part of the code… or we should memorize it.

For example, if the interviewer wants me to “title case a sentence”, I knew that I have to toLowerCase() everything. then use replace method, then use regex to find all the 1st letters, then add in another function where they will be transformed into uppercase letters. But I do not know the exact combo I should use in regex.

Do I still get a pass?

I don’t think anyone would ask questions involving regular expressions on an interview. As far as I know companies try to stick to more general concepts than syntax semantics that are constantly referenced by people even with experience.

1 Like

thank you. let’s say that hypothetically I got a question that involved regex, I can politely say that I can solve all the other parts of the code, (just like I described above how will I title case a sentence), but the regex part I don’t remember.

can I politely tell them that?

There’s no combos in regex, you just has to memorize the regex elements. I know it looks hard but try to have fun with it for a while and you’ll see it’s not that hard.

I actually found this site just today and I loved it, it will show you all regex elements and then give you some challenges. You’ll feel a lot more confident if you can pass on them all. And you can search or ask for help if you get stuck.

1 Like

A company actually asked you regex questions in an interview? :face_vomiting:

hahaha! no… that’s why I said : “hypothetically”

I will try my best! (20 characters)

I did several interviews. None of them had a regex question. But it’s good to learn because there will be times it can solve a problem easily.

1 Like

I did learn it through freecodecamp’s curriculum. It’s just that after a few weeks forgot most of the stuffs like what do those symbol mean…

thanks for the info though!

Yeah, I usually have to look up anything beyond the basics. But it is a really powerful tool. I’m planning on spending some more time working on it. There are times that it’s saved my life in one line of code.

1 Like

Regex is a great thing to know. For certain types of problem, you can’t do without it. But it doesn’t come up very often in regular coding. Even when it does, such as validating a phone number or password or email, it’s probably better to just look up a well-tested solution rather than write your own.

It’s pretty unlikely that you will get a regex problem in an interview, in my opinion. And the problem you mention (title case a sentence) does not require it.

1 Like

I don’t think anyone is expected to have memorized things like complex regex expressions. In the real world, developers use resources like MDN’s page on regex expressions any time it comes up. It can’t hurt to be a bit more familiar with them, of course.

1 Like