How Do Regular Expressions Really Work?

  Рет қаралды 30,019

Low Byte Productions

Low Byte Productions

Күн бұрын

Пікірлер: 44
@wlockuz4467
@wlockuz4467 3 жыл бұрын
Wow this is mind blowing! I have read a lot of theory about Regex but I have never seen a practical example so well done! You earned a sub!
@LowByteProductions
@LowByteProductions 3 жыл бұрын
Thanks WloCkuz - much appreciated!
@fabiodan30
@fabiodan30 4 жыл бұрын
Thanks for spreading the good word on parsers and virtual machines. It's important work, what you're doing here, and more people should do it. Liked and subscribed!
@kylefong2888
@kylefong2888 3 жыл бұрын
YOU'RE ABSOLUTELY SICK!!! I geek out about stuff like this, this is so cool. Thank you for taking the time to share your knowledge!
@huizhang7413
@huizhang7413 Жыл бұрын
Holy shit, I spent 2 weeks learning the principles of compilers. I learned tons of terminology, regular expressions, NFA, DFA, and how to convert one into another. But when it came to writing a regular expression engine, I still didn't know where to start. But this video taught me in just 20 minutes!!! A big thank you to you.👍
@imsherry7225
@imsherry7225 4 жыл бұрын
You Are A Great Person ❤️✌️
@LowByteProductions
@LowByteProductions 4 жыл бұрын
Thanks Sherry ☺️
@imsherry7225
@imsherry7225 4 жыл бұрын
@@LowByteProductions My Pleasure
@ben.faerber
@ben.faerber 3 жыл бұрын
Wow, I'm so happy to have found a channel like this about my favorite language! I'm writing an APL clone in Javascript and will have to use your videos for research!
@LowByteProductions
@LowByteProductions 3 жыл бұрын
Thanks Ben - hope they come in handy!
@LachlanMiller
@LachlanMiller 2 жыл бұрын
This was really good, thanks.
@AmanGupta_Dev
@AmanGupta_Dev 4 жыл бұрын
After watching your videos, I am pretty much confident that all those curious questions / doubts I had, will be solved ! once and for all !
@LowByteProductions
@LowByteProductions 4 жыл бұрын
I certainly hope so!
@ShaunakDe
@ShaunakDe 4 жыл бұрын
Thanks for doing this. It was very instructive to watch.
@poof65
@poof65 4 жыл бұрын
Very interesting, even if I don't have seen it at the best moment. End of day on my couch, I was starting to fall asleep at the end of the video 😅
@LowByteProductions
@LowByteProductions 4 жыл бұрын
I commend your effort given the circumstances 😁
@yapdog
@yapdog Жыл бұрын
Wildcard (.) matches everything but newline ( ). At least in most engines. Great video, very timely for me 😁👍
@ratchet1freak
@ratchet1freak 4 жыл бұрын
a better way than backtracking is to instead have an array of current states and go character per character. Then when a choice is to be made on a state you duplicate that state and simulate both choices. This lets you avoid the most common pitfall of regex implementations If a state fails to match the character you drop it from the state array. The regex matches when you get to the end of the string with a state that is at the end of the regex.
@dentjoener
@dentjoener 2 жыл бұрын
For repetition (including all of the variants) I usually use a generic repeat pattern with min and max, and for unbounded versions I set max to some incredibly high value. (MAX_SAFE_INTEGER or something). This allows me to do the following tranformations: ? -> repeat(0,1), * -> repeat(0,MAX), + -> repeat(1,MAX),... etc
@gimmemoreborisbrejcha9794
@gimmemoreborisbrejcha9794 3 ай бұрын
I believe implementing such an engine can be easier with usage of some nfa implementation, and being able to combine them. I actually implemented one that contains very advanced features of modern engines, like captures and such.
@sshh6285
@sshh6285 3 жыл бұрын
subscribed, awesome, unique content
@BryanChance
@BryanChance Жыл бұрын
I learned about regex when I was trying to learn Perl. Oh yes, the syntax is absolutely mind boggling to me at the time. (I'm talking about Perl's syntax) Just kidding but it's close. LOL After about 8 months, it finally clicked; the regex syntax made sense. Anyhow, Perl and regex are perfect together. I think learning Perl and regular expression broke my brain. LOL Then I found out about sed, awk, and all the other text utilities commands like cut, sort, uniq, tr, etc.. I couldn't imagine the complexity of writing a regex engine. But I 'll find out watching video!. Thank you for sharing your work.
@LowByteProductions
@LowByteProductions Жыл бұрын
I learned perl a long time ago - probably before I had any real idea what I was doing 😁 I look back very fondly on it, and remember it being amazing for regex and text processing in general.
@AnonymousAccount514
@AnonymousAccount514 Жыл бұрын
Mind Blown
@JSRFFD2
@JSRFFD2 4 жыл бұрын
This was a very good video, thank you! I wonder if backtracking could be handled more elegantly with recursion. I also wonder if backtracking or recursion would be better suited to handle something like a|b
@LowByteProductions
@LowByteProductions 4 жыл бұрын
For your first point, yes I think you could use recursion, although a bit of alteration would be needed. In that case, you're using the call stack itself as the data structure that keeps track your state. The call stack is however a limited size (varies from environment to environment), and JS unfortunately doesn't have tail calls. For your second point, alternations need a bit of extra modelling (in parsing), but are essentially just a new kind of element type. So in the stateMatchesStringAtIndex function you could add a new case that iterates through the possibilities, trying each one until it finds one that works.
@anonymoussloth6687
@anonymoussloth6687 3 жыл бұрын
Can u tell me where i can learn to create a more complicated one? I have studied finite automata and compiler design so I am not new to regex and dfa, but I want to learn how to implement onw from scratch
@JayDee-b5u
@JayDee-b5u Жыл бұрын
Why are you using arrays of arrays?
@mluevanos
@mluevanos 2 жыл бұрын
Thanks for bringing the advanced JavaScript topics to YT.
@eugenegordo3130
@eugenegordo3130 4 жыл бұрын
Thanks for the video! Tell me please which font you using in the editor?
@LowByteProductions
@LowByteProductions 4 жыл бұрын
I believe it's inconsolata
@eugenegordo3130
@eugenegordo3130 4 жыл бұрын
Thanks!
@MrLiquitorleaveit
@MrLiquitorleaveit 3 жыл бұрын
I´m feeling like I´m a bazillion hours away from producing code like this. Watched the whole video though, kind of fascinating how it all adds up in the end.
@LowByteProductions
@LowByteProductions 3 жыл бұрын
Hey - you'll surprise yourself with how much less than a bazillion hours it can be if you focus on the right stuff. Anytime your reading/watching/trying to understand something that makes you a bit uncomfortable because it's not immediately clear - that's actually a great sign! Follow it up with a trip to Wikipedia or a Google search. Keep exposing yourself to tough stuff. Very quickly concepts will fall into place, and you'll be able to look into even tougher stuff. Honestly it's one of the things I wish I had been more conscious about earlier in my career.
@laujimmy9282
@laujimmy9282 Жыл бұрын
​@@LowByteProductions this comment is really helpful for many of us ❤ thx
@maxdemian6312
@maxdemian6312 Жыл бұрын
I always read regex as reghex
@panjak323
@panjak323 5 ай бұрын
Regex is much easier once you learn DFA and NFA and regular grammars. Then it's just syntactic sugar, and can be implemented as such.
@calvinlucian387
@calvinlucian387 4 жыл бұрын
Nope. Still can't work with regex. 😪 Great tutorial tho ❤
@LowByteProductions
@LowByteProductions 4 жыл бұрын
Give super-expressive a try (github.com/francisrstokes/super-expressive). Might help you better wrap your mind around the idea!
@poof65
@poof65 4 жыл бұрын
Regex is love, Regex is life 😍
@calvinlucian387
@calvinlucian387 4 жыл бұрын
@@LowByteProductions Thanks! That's a gem of library! ✌
@fylink
@fylink 4 жыл бұрын
Your algorithm misses nested qunatificators. For example, imagine the expression /([A-Z].*){3}#/ matched against the string 'AxsaBsaxsaCsaxas#'. Your algorithm will fail and it would need drammatic modifications to cope with that.
@koenderbb5191
@koenderbb5191 3 жыл бұрын
Zeg eens eerlijk, ben je Nederlands?
@LowByteProductions
@LowByteProductions 3 жыл бұрын
Nee helaas kom ik uit Engeland. Maar mijn dochter is wel Nederlands.
Regular Expressions - Computerphile
17:19
Computerphile
Рет қаралды 249 М.
JavaScript Is Weird (EXTREME EDITION)
21:29
Low Byte Productions
Рет қаралды 691 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Making WAVs: Understanding, Parsing, and Creating WAV Files in JavaScript
23:37
Regular Expressions (Regex) Tutorial: How to Match Any Pattern of Text
37:55
Defining Regular Expressions (RegEx) - Computerphile
18:29
Computerphile
Рет қаралды 88 М.
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel (kiwi)
Рет қаралды 242 М.
Learn Regular Expressions In 20 Minutes
20:52
Web Dev Simplified
Рет қаралды 1,3 МЛН
Using Regular Expressions - Computerphile
11:39
Computerphile
Рет қаралды 126 М.
Getting up in another processes memory
46:54
Low Byte Productions
Рет қаралды 15 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН