An obsession about regular expressions

while I’m taking regex challenges, I keep imagining that we gonna use our regex skills on an unknown text so we have to deal with this obstacle. so far all challenges have a string we can see, but when running a website that allows text input, we may have a general idea of what that text input will be but I keep imagining that gonna have to write regexes for text we don’t know, so somehow I feel like we need to be prepared.
any advice on how to be ready for the unknown?
feel free to add on what you think?

That’s the point of regex - dealing with the unknown. But it also depends on what you mean. I mean, you can’t make some catholicon regex that will work for any task - they have to be made for a specific task. Like, you need to accept only usernames that start with a letter which is followed by 2-11 letters or numbers. You need to split a string using a specific string as a boundary). Another example that would be the telephone number validator.

I’m not sure what you mean, “so far all challenges have a string we can see”. I mean, yes, FCC does show you what it is testing. That is because it might be too hard otherwise. There are other sites that just offer coding challenges. They are “notorious” for trying your solution against a bunch of hidden tests, trying to find every possible point of failure.

And just to add… regex is weird and confusing. It is also incredibly challenging. There have been plenty of times where a simple like of regex has saved me 2-5 lines of ugly code.

1 Like

I dont understand why you focus on the unknown. For me, what matters is the known and more precisely, to know very well exactly what you look for and ofc., to be able to convey it via the regex properly. You want your regex to be as universal as possible, or at least to cover the possible text input you are likely to receive, so it works on every and any input. To be able to do that, it happens with practice and testing. Feed your regex with possible inputs and see how it behaves. In what istuations it doesnt serve the purpose you imply it should.

PS: just wanna mention, while regex can be extremely complicated to come up with, its also invaluable when working with strings and can save you lines of code, often removing the need to use other methods, or even chained ones, functions, loops etc. It does all in one line(or one precise expression).

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.