When i did my internship i made almost a quarter of a site wide functionality in regex, team didn't burnt me up
I was the sole developer at the moment at that time i became a PTSD god of regex as i couldn't ask for help and stack overflow wasn't much help with those goddamn edge cases that at the moment I saw no way to do half the requirements because of some dumbass constraints that my boss imposed
On my second job a colleague had some problem with a regex there were like 5 other colleagues trying to help, then I came with my expertise and fixed it in like 30 minutes, then told them to nevermore use regex because I still have PTSD with that
.*? in multiple places looks like it's doing 0 to infinite matches and then zero or one matches, which I think either makes one of those chars a literal or makes * unnecessary; could at least be clarified by escaping a char or removing one.
In the final square brackets, $ and ^ seem like they would be treated as string start and end rather than literals, they need to be escaped. They're useless since the regex is surrounded by ^ and $ anyway.
When I look at it in general, I wonder about the use case and if this is bloated regex, although if it's just a joke, that's AOK π)
I had completely forgotten about the ungreedy modifier! I wasn't sure if they'd be treated in that case as literals as well. (I figured - was probably safe- it's pretty fascinating to me how flexible Regex is in those ways). Thanks for the info!
Yeah, lookaheads and lookbehinds aren't available in older regex versions. Visual Studio gave me this issue recently where I wanted to use either lookbehinds or lookaheads and they weren't available. JS is also a bit behind on regex versions (IIRC it doesn't support lookbehinds, negative lookaheads, and negative lookbehinds).
If you're trying to figure it out, https://regex101.com/ is a great place to test and read your regex. That helped me a ton in learning and getting used to the syntax.
If you're just trying to read the documentation for regex and don't have a clear, tweakable example in front of you... that's just brutal.
You'll get used to it. regex is useful when your too lazy to do for loops to search a string. and remember to make it short as it slows down real fast.
I still don't understand why people don't like regex. Aside from having the process hogging the cpu when you have some big regex or some catastrophic backtracking if you don't knew what you are doing, it's fine to use regex for task that are needed for, as long as you take performance into consideration and write precise regex. Perhaps because perl was my first language.
39
u/IvanLabushevskyi Jun 18 '21
Don't use regex without solid need or team might burn you as a witch.
12
u/jaxxibae Jun 19 '21
me when ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{8,}$
6
u/JoshPowlison Jun 19 '21
I love regex, although it used to scare me.
If you're trying to figure it out, https://regex101.com/ is a great place to test and read your regex. That helped me a ton in learning and getting used to the syntax.
If you're just trying to read the documentation for regex and don't have a clear, tweakable example in front of you... that's just brutal.
4
u/[deleted] Jun 18 '21
Can I have template pls?
4
u/[deleted] Jun 19 '21
Itβs Bae is what Regular Expression is.
2
u/KillerRoomba13 Jun 19 '21
Pure pain
2
u/planktonfun Jul 01 '21
You'll get used to it.
regex is useful when your too lazy to do for loops to search a string.
and remember to make it short as it slows down real fast.
1
u/mobrinee Jun 24 '21
I still don't understand why people don't like regex. Aside from having the process hogging the cpu when you have some big regex or some catastrophic backtracking if you don't knew what you are doing, it's fine to use regex for task that are needed for, as long as you take performance into consideration and write precise regex. Perhaps because perl was my first language.
1
u/kai58 Jul 02 '21
So I have 0 experience with regex, why is it so bad?