I've always wondered why they are called "regular expressions".. when in fact, their more like "special-ability-superhuman expressions". hahaha. Jokes aside, I've often decided to learn regex properly, but then somehow I never get past the 0-9 a-b... :D
On a sidenote, if your code is riddled with regex (highly optimised and beautiful) does it not make it more difficult for less experienced devs to make changes to your code? I guess I am asking if we should weigh up using regex, versus simpler string manips?
Yeah, sometimes it just makes sense to use regex, especially when looking for patterns in text. It's easier to say "look for \([0-9]{3}\) [0-9]{3}\-?[0-9]{4}" than:
look for a ( character, if you find one, check that
When tdd is viable, rex can be expressed very thoroughly in tests. They need to be tested differently anyway because of their versatility, so those tests go a long way to show what it should/not do
Rex is a little like awk. Despite my love for it, I use it in code judiciously - just for the sake of who-comes-next. If the thing can be done effectively otherwise, I'll probably use the otherwise. ...to a point. I'm not going to trade a rex for an O^n^6 for the sake of who-comes-next lol.
For my own uses, though? Wait.. that form was misconfigured and now you have 840 contest submission emails you're manually copying/pasting to a spreadsheet?!?! Fwd those and give me 4 minutes. π€
I've always wondered why they are called "regular expressions".. when in fact, their more like "special-ability-superhuman expressions". hahaha. Jokes aside, I've often decided to learn regex properly, but then somehow I never get past the 0-9 a-b... :D
On a sidenote, if your code is riddled with regex (highly optimised and beautiful) does it not make it more difficult for less experienced devs to make changes to your code? I guess I am asking if we should weigh up using regex, versus simpler string manips?
Yeah, sometimes it just makes sense to use regex, especially when looking for patterns in text. It's easier to say "look for
\([0-9]{3}\) [0-9]{3}\-?[0-9]{4}
" than:(
character, if you find one, check that0
,1
,2
, ...0
,1
,2
, ...0
,1
,2
, ...)
character...I think you can always help with understanding of regex by commenting and naming, just like you would with other code items.
Yep, very good. Perhaps even add the expected result as part of the comment.
When tdd is viable, rex can be expressed very thoroughly in tests. They need to be tested differently anyway because of their versatility, so those tests go a long way to show what it should/not do
regex101.com/ is a godsend when it comes to understanding someone else's line noise.
Rex is a little like awk. Despite my love for it, I use it in code judiciously - just for the sake of who-comes-next. If the thing can be done effectively otherwise, I'll probably use the otherwise. ...to a point. I'm not going to trade a rex for an O^n^6 for the sake of who-comes-next lol.
For my own uses, though? Wait.. that form was misconfigured and now you have 840 contest submission emails you're manually copying/pasting to a spreadsheet?!?! Fwd those and give me 4 minutes. π€
:D hahaha. Seeing a good regex in action is literally like magic! Aloha-regex and BANG - magic.