+ 3
[Solved] When is RegEx safe and best to use?
This is just out of curiosity. Why is it usually advised against when matched material is prone to changes due to updates in matching conditions? I see people saying it's complicated and hard to update. Does it only have to do with a next coder in your position in some work place? Or other issues in mind? Why do even the seasoned coders say it's hard to change?
4 Réponses
+ 1
Regexes tend to be complex by their nature. But, when well crafted, they are safe. It's just advisable to document them, so other developers can improve and/or update.
+ 1
The secret is to start regexes small and simple, then going harder as you validate
+ 1
Emerson Prado I will definitely take heed and try to go stepwise as you said, testing for each condition and see what's captured. I'll just try it for one type, first. Thank you for the advice.
Editing in a note for fellow noobmates:
positive lookahead (? = ) doesn't capture chars with stated conditions, they do assertions, but I was meaning to say I'll start without them and then add one p. a for each condition slowly.
I kind of did it, but I have a problem with the special character one. It accepts only one. Will put it up once I'm done, although I'll say even a simple Regex that I can do looks like alien talk to me once I've stayed 5 min away from it, and it looks as messy as, I'm sorry, but, diarrhea. At least mine does.
0
Emerson Prado Cool, thank you for clearing this up. So I'm gonna do a password validator with positive lookaheads then and hit back the discussions if I start splitting hairs :D
... I think I'll have a problem, though when I try to implement an expression that matches at least two of 3 or 4 char types...
Thank you :-)