Regex is HARD!

  Рет қаралды 11,408

ArjanCodes

ArjanCodes

Күн бұрын

Пікірлер: 58
@ArjanCodes
@ArjanCodes 9 ай бұрын
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
@ToddVanyo
@ToddVanyo 9 ай бұрын
Always remember the adage: if you think regex is the solution to your problem, you now have 2 problems.
@twelvethis3979
@twelvethis3979 9 ай бұрын
Very nice video, thank you, Arjan. I was just wondering: What specifically is bad about REGEX_1, and why are REGEX_2 and REGEX_3 better?
@PanduPoluan
@PanduPoluan 9 ай бұрын
Unclassed greedy operators.
@todd.mitchell
@todd.mitchell 9 ай бұрын
Thanks! More on optimizing regex please.
@randomdude2540
@randomdude2540 9 ай бұрын
Love the new format! Thanks for the content.
@ArjanCodes
@ArjanCodes 9 ай бұрын
I'm glad you're enjoying the new content! :)
@maleldil1
@maleldil1 9 ай бұрын
My recommendation from experience is to have _a tonne_ of tests for your regex, especially if it's very important for your application like email checking is. In Python with pytest, you can use parametrised tests to load valid and invalid emails from text files and just check that the output is correct. As time goes by and you find some false positives and negatives, you can add them to your test data to ensure you've fixed the bug.
@edgeeffect
@edgeeffect 13 күн бұрын
Absolutely! Treat regex as if it's a malicious enemy.
@obinnaokonkwo2465
@obinnaokonkwo2465 9 ай бұрын
PYtips. Great job Arjan.
@Tesfamichael.G
@Tesfamichael.G 9 ай бұрын
Tip of the week
@silkogelman
@silkogelman 9 ай бұрын
Tuesday tips? Did you mean to say Code Snippets by ArjanCodes? 😁
@Djellowman
@Djellowman 9 ай бұрын
Goed video format! Kort & informatief.
@ArjanCodes
@ArjanCodes 9 ай бұрын
Dankjewel! 😊
@MartinPHellwig
@MartinPHellwig 9 ай бұрын
I'd say it should be "Arjan in shorts", I trust you can come up with your thumbnails 😊
@dragonfly-7
@dragonfly-7 9 ай бұрын
One the naming question for the new series: Stay with "tuesday tips". Reason ? The 1st thought is the best one most of the time.
@cheweh842
@cheweh842 9 ай бұрын
Valid email addresses aren't really possible to match with regular expressions, anyway. At least, not all possible addresses as allowed by the RFC. For that reason I don't know what regex I should use for email addresses, if anything at all.
@Draggeta
@Draggeta 9 ай бұрын
From what I've heard, it is best just to check for only one @ sight with something before and something after. Now I wonder how to check for only one @ character in a string....
@MichaelONeillIrish
@MichaelONeillIrish 9 ай бұрын
What I've had the most success with is doing a trivial check on the input for optional form validation, and then actually trying to send an email to the address. For the pattern, checking for non-whitespace characters, then an @, followed by more non-whitespace characters, then a period, then more non-whitespace characters is generally sufficient. A false positive match isn't really all that harmful, and you shouldn't get any false negatives, so it tends to ensure users have put in something vaguely, potentially correct before submitting the form. Or, like @Dragetta said, just check for an @ symbol in the string and be done with it. Then you try sending an email, and if it's successfully delivered, it's valid. If it fails to deliver, you can either stop there, or look into more robust retry logic e.g. using a pending registrations table in the DB that you try to verify several times before removing to avoid cluttering up your user table.
@Draggeta
@Draggeta 9 ай бұрын
@@MichaelONeillIrish i like the check to send an email. However, domains don't need to have a period and spaces are allowed in the email address. That is what makes validating email addresses such a pain.
@hcubill
@hcubill 9 ай бұрын
Very very interesting! Sparked many thoughts ❤
@OradWasTaken
@OradWasTaken 9 ай бұрын
arjan's ardvice
@cfk-oz
@cfk-oz 9 ай бұрын
Maybe do a video on Panel or Panel vs Dash
@lxathu
@lxathu 9 ай бұрын
And be careful when you create your own parsing algorithm in order not to use a regular expression because routines can be hard to read, can be sub-optimal and can contain an eternal loop. Or even a lot of them.
@uwegenosdude
@uwegenosdude 9 ай бұрын
Great video again. Thanks a lot. Is there a way in Python to limit the execution time of a regex to prevent such a scenario like a ReDoS attack?
@edgeeffect
@edgeeffect 13 күн бұрын
Write A LOT of tests!
@slawek6302
@slawek6302 9 ай бұрын
Codjan Tips or Code-jan Tips
@copperfield42
@copperfield42 9 ай бұрын
how about calling it: Arjan's Tips weekly tips developers tips
@joaopedrorocha5693
@joaopedrorocha5693 9 ай бұрын
Why not "Arjan Tips"? Nice, simple and reminds the channel name kk
@anonapache
@anonapache 9 ай бұрын
If you use such a long regex, you probably shouldn't use one. Also, to catch all possible triggers for an "infinite" loop, use a timeout.
@QwDragon
@QwDragon 9 ай бұрын
Length is not a problem. Regex can't be infinite, but it can be exponential, even a short one.
@anonapache
@anonapache 9 ай бұрын
@@QwDragon Length might not be a technical problem, but for sure a human one.
@dynamicgrad3820
@dynamicgrad3820 9 ай бұрын
Automata Theory (DFA) helps to write better regex expressions ;)
@maleldil1
@maleldil1 9 ай бұрын
Only very simple regexes can be directly converted to/from DFAs. As soon as you get into stuff like backtracking and non-greedy matching, the conversion becomes convoluted. I believe it's rarely worth it.
@d3stinYwOw
@d3stinYwOw 9 ай бұрын
Since we are in the realm of web, maybe some review on usage of HTMX for python folks out there? Would be great to see that here! :)
@rrwoodyt
@rrwoodyt 9 ай бұрын
Cue the XKCD about regular expressions….
@edgeeffect
@edgeeffect 13 күн бұрын
As long as it's "Perl problems" or "regex golf" and not "save the day"
@ikari3k
@ikari3k 9 ай бұрын
In terms of regex readability isn't adding comments to your regex using re.VERBOSE and rstring just a standard to be used? Do you find it helpful when coding complex matches?
@wilk85
@wilk85 9 ай бұрын
Maybe everyday tips?
@ramb0lxmb
@ramb0lxmb 9 ай бұрын
regex is the perfect ai use case. something fairly easy for a computer to translate from plain written language, but looks crazy to a human.
@maleldil1
@maleldil1 9 ай бұрын
There's a significant chance that the AI will hallucinate the regex, and it's really hard for the human to catch that.
@edgeeffect
@edgeeffect 13 күн бұрын
... if the AI could be trusted to get it right... which it can't.
@juanjoseexpositogonzalez1126
@juanjoseexpositogonzalez1126 9 ай бұрын
Easy Python Pills (to swallow) for the name?
@johnabrossimow
@johnabrossimow 9 ай бұрын
Writing Regex is kind of like writing raw sql, why does sql have abstraction libraries but regex doesn't?
@Casimistico
@Casimistico 9 ай бұрын
Can’t catch which regex is evil just like my regexs cant catch valid strings
@diegol_116
@diegol_116 9 ай бұрын
Then the double videos per week started... Great!
@EvenTheDogAgrees
@EvenTheDogAgrees 9 ай бұрын
Regexes are OK, but I consider them write-only code except in the most trivial cases. They're easy to write, but hard to read.
@QwDragon
@QwDragon 9 ай бұрын
It's obvious that the first is bad bacause of constraction before @ sign in form of ([smth]?[other]*)*
@edgeeffect
@edgeeffect 13 күн бұрын
A "clever" regex is a guaranteed way to show-off what a 10X ninja rockstar developer you are... and your team will "thank" you for it for many many years after you write it.
@masterofIich
@masterofIich 9 ай бұрын
I dont think Regex1 will catch all email adress
@Ruskialt
@Ruskialt 9 ай бұрын
Regex are so tedious they need be verified with unit tests.
@ashleymcgee3536
@ashleymcgee3536 9 ай бұрын
Oooh yeah. We’ve reDos’d ourselves before.
@PanduPoluan
@PanduPoluan 9 ай бұрын
Greedy operators are nearly always bad, except when they're at the very end.
@RajveerSingh-vf7pr
@RajveerSingh-vf7pr 9 ай бұрын
DickVanDyne Tips
RegEx Roman Numerals - Computerphile
17:14
Computerphile
Рет қаралды 86 М.
The BEST No-Nonsense VSCode Setup for Python Devs
26:05
ArjanCodes
Рет қаралды 27 М.
Thank you Santa
00:13
Nadir Show
Рет қаралды 29 МЛН
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН
7 Functional Programming Techniques EVERY Developer Should Know
21:35
Regular Expressions (Regex) Tutorial: How to Match Any Pattern of Text
37:55
Is it worth it to call Rust from Python with PyO3?
8:50
EKB PhD
Рет қаралды 1,4 М.
Python 3.12 Generic Types Explained
18:27
ArjanCodes
Рет қаралды 64 М.
5 Ways First Principles Thinking Helps You Code Better
10:19
ArjanCodes
Рет қаралды 27 М.
Regular Expressions - Computerphile
17:19
Computerphile
Рет қаралды 246 М.
Protocols vs ABCs in Python - When to Use Which One?
15:31
ArjanCodes
Рет қаралды 41 М.
Python Regular Expressions - Computerphile
22:16
Computerphile
Рет қаралды 55 М.
A Simple & Effective Way To Improve Python Class Performance
12:40
Thank you Santa
00:13
Nadir Show
Рет қаралды 29 МЛН