C++ Tutorial 19 : C++ Regular Expressions

  Рет қаралды 84,494

Derek Banas

Derek Banas

Күн бұрын

Пікірлер: 129
@ngneer5804
@ngneer5804 Жыл бұрын
Old video, but in case anyone watches it, there are some mistakes: 1. std::smatch::size() does not return the number of matches! it returns the number of capture groups plus 1 for the whole match! The reason he gets 2 is because he put the whole string inside a capture group (round brackets). So one for the whole match, and one for the capture group. If he'd use another set of these brackets, he'd get 3. 2. std::smatch::str(1) does not return the first match! it returns the first capture group! 0 is the whole match, but because he put the whole string inside a capture group, using 0 would net him the same result as 1. 3. \w also matches an underscore (_), and naturally, underscore wouldn't be matched with \W (i.e. capital letter w). In general, using capturing groups (round brackets) is expensive and shouldn't be used if there's no point for it, and in this video there really wasn't a point. Even if you need to use parenthesis, you can disable capturing by adding ?: in the beginning. No disrespect to the author by the way! The video was decent overall!
@gigamungus5764
@gigamungus5764 6 жыл бұрын
I have an interview coming up in a few days for c++ and a week ago i had never even looked at the language, you have no idea how grateful I am that you started making this when you did
@derekbanas
@derekbanas 6 жыл бұрын
Thank you :) I'm happy I could help. Best of luck on your interview
@abeerkh4493
@abeerkh4493 2 жыл бұрын
Thank you so much for your hard work on your videos. I have learned more from you than my university doctors. The way you explain stuff in a very simple and straight forward way is AMAZINGGGG. I really appreciate your efforts. THANK YOUUUU
@derekbanas
@derekbanas 2 жыл бұрын
Thank you for taking the time to tell me I helped :) I'm very happy you are enjoying my videos
@vojar3692
@vojar3692 6 жыл бұрын
Huge appreciation for your determination, free educational videos and effort to help everyone! Hope your 2019 is gonna be ++awesome! All the best!
@derekbanas
@derekbanas 6 жыл бұрын
Thank you very much :) I wish you all the best in the new year!
@justsurajp
@justsurajp 2 жыл бұрын
At 26:48, wouldn't the "." (dot) accept any character instead of period character? Would it be more meaningful to use "\\." instead to specify we are looking for a period and not just any character?
@gigamungus5764
@gigamungus5764 6 жыл бұрын
in the final example you didn't escape the dot, so it was matching any character, not just "."
@derekbanas
@derekbanas 6 жыл бұрын
Whoops sorry for the typo. I wrote the code largely out of my head
@jonajo261
@jonajo261 3 жыл бұрын
I don't undestand, in PrintMacht2 you don't initialize lastMach wtf is going on ; how can you check for the value if lastMatch is empty
@samitkapoor53
@samitkapoor53 4 жыл бұрын
at 26:50 wont we add another '\' before '.' to escape the '.' in reg14?
@Skooma150
@Skooma150 Жыл бұрын
Thanks for this video. Been a while since I used regex and the syntax is very confusing, especially when you're rusty. Spent hours on stack and this is the first thing that helped me make any progress.
@sabrinanastasi5809
@sabrinanastasi5809 Жыл бұрын
Hands down the best regex tutorial, thank you!!!!
@exodus8814
@exodus8814 6 жыл бұрын
This is wonderful :) Thank you very much Derek, you never fail to upload such high quality and clear videos, you are awesome! Thanks :)
@derekbanas
@derekbanas 6 жыл бұрын
Thank you for the nice compliment :) I try to do my best
@exodus8814
@exodus8814 6 жыл бұрын
Derek Banas Wow thanks for the fast reply too :)
@feraudyh
@feraudyh 3 жыл бұрын
There's one thing I did not get: lastmatch is not set anywhere, so why should it represent the end?
@shawnarmstrong3339
@shawnarmstrong3339 2 жыл бұрын
I looked into this. The default constructor for sregex_iterator creates an end-of-sequence iterator; from the documentation : "The default-constructed std::regex_iterator is the end-of-sequence iterator. When a valid std::regex_iterator is incremented after reaching the last match (std::regex_search returns false), it becomes equal to the end-of-sequence iterator. Dereferencing or incrementing it further invokes undefined behavior."
@jamesday2386
@jamesday2386 Жыл бұрын
@@shawnarmstrong3339 life saver, thank you
@bryany3241
@bryany3241 4 жыл бұрын
Don't you need to use double backslashes in c++ regex, to escape the escape character (the backslash)?
@nicklansbury3166
@nicklansbury3166 6 жыл бұрын
Derek, as always, another very informative tutorials. Thanks for that. I was wondering. Now that you've done a 'How to Make Video Games' series and you are currently doing a 'C++ Tutorial' series, would you consider combining the two subjects? I'd love to see a 'How to Make Video Games using C++' series. Just a thought.
@kesuskim6072
@kesuskim6072 6 жыл бұрын
yeah, possibly using Unreal engine or SFML!
@nicklansbury3166
@nicklansbury3166 6 жыл бұрын
Actually I'd prefer to do something 100% in code rather than use a visual editor. There's already a ton of UE4 tutorials around. Getting down and dirty with the code is what interests me.
@derekbanas
@derekbanas 6 жыл бұрын
I'll see what I can do. I can make a basic graphics engine and if people watch it I'll continue making videos. I love covering complex topics, but they are a double edged sword. They are harder to make and then it is disheartening after I make one to see that only 20 people watched the whole video.
@derekbanas
@derekbanas 6 жыл бұрын
I'm working on a UE4 tutorial
@kesuskim6072
@kesuskim6072 6 жыл бұрын
wow, making basic graphics engine!! :) very interesting derek, I'm very interested (y)
@muhsenalkhalidy7849
@muhsenalkhalidy7849 3 жыл бұрын
Hello , i included the regex library and when type std::smatch sm; the compiler gives error says that smatch is not a memeber of std? plz help
@MatthewBendyna
@MatthewBendyna Жыл бұрын
Does the carrot symbol still mean begins with in C++ like in Python and C# when not inside the brackets? (assuming brackets mean set)
@shreyshah4220
@shreyshah4220 4 ай бұрын
Great video! Just use the "using namespace std" at the start! It is really off putting.
@MrinmoyHaloi
@MrinmoyHaloi 2 жыл бұрын
i have a problem where i need to use the dotall flag. How can i do that in c++ ?
@Omar-dd2lw
@Omar-dd2lw 6 жыл бұрын
i study programming in college ,and cause of your videos i just got 60/60 (full mark) in C++ ,thank you so much
@derekbanas
@derekbanas 6 жыл бұрын
Awesome! Great Job :)
@MochrieTVHotS
@MochrieTVHotS 5 жыл бұрын
Fantastic video! :) The length is absolutely justified by the content.
@derekbanas
@derekbanas 5 жыл бұрын
Thank you very much :)
@russellmcnamara6107
@russellmcnamara6107 6 жыл бұрын
Derek I am your biggest fan my name is Russ I have been in jail for a year and I could never stop thinking about you and your videos they're so amazing I couldn't stop about how you said hello Internet and everything about your videos and you I hope your doing good I love your videos so much
@bobhutchinson3638
@bobhutchinson3638 5 жыл бұрын
Seems like you are okay for now!
@jakesmith6853
@jakesmith6853 6 жыл бұрын
As usual, big thanks to you :). Preparing for a tech interview with the help of your videos. You rock!
@derekbanas
@derekbanas 6 жыл бұрын
Thank you very much :) I wish you the best of luck on your interview!
@ashleyrawr74
@ashleyrawr74 5 жыл бұрын
Hi, I'm trying to use the iterator but I'm getting a "regex_iterator not dereferencable" bug message in output. Any ideas on how to fix this?
@derekbanas
@derekbanas 5 жыл бұрын
I have working code in the description. Try comparing it to yours using diffnow.com
@limyautito3298
@limyautito3298 2 жыл бұрын
How can I use the regex library?
@gnujeu
@gnujeu 6 жыл бұрын
I just wanted to say I figured out the application... Your videos are very helpful
@derekbanas
@derekbanas 6 жыл бұрын
I'm happy I could help :)
@kholiyamails1257
@kholiyamails1257 2 жыл бұрын
there was the question by amazon related regular expression ........ if starting char match with last char (example : aba , ab , aa) aba and aa would be true and I was given only this line regex regular_expression("________________") ,and I only was to write inside it ,so what should be written inside it .🙂
@alonsamuel934
@alonsamuel934 6 жыл бұрын
Hi!! Thank you very much for the tutorial!! it helped me understand some basic ways to use regex in order to shorten my life in searching string stuff. :) I wanted to ask how did you use currentMatch? I thought that you would first declare it as an iterator and then fill it with data. I didn't see where did you put data in it... I also didn't understand how did you declare it with parenthesis ? If you could explain a bit more for me... thank you !!
@GeckoSharky
@GeckoSharky 6 жыл бұрын
"Any call to regex_match or regex_search with the match_results object as argument sets this value to true, even if the function does not succeed in finding any match." You sure that ready() indicates that there is a match or not? Doesn't sound like it according to the docs.
@derekbanas
@derekbanas 6 жыл бұрын
Thank you for pointing that out. I bungled my explanation. It returns true if the test for results is finished. I updated the code on my site.
@terrylim4725
@terrylim4725 5 жыл бұрын
Around the 17min mark of your video: Using: std::regex reg7 ("([^ ]\..\..\.)"); Gave this error: warning: unknown escape sequence: '\.' Changing the line to : std::regex reg7 ("([^ ]\\..\\..\\.)"); resolved the error, and the code could compile
@abderrazakschannel4491
@abderrazakschannel4491 2 жыл бұрын
how to do the apostrophe in regex?
@AdityaDodda
@AdityaDodda 6 жыл бұрын
In PrintMatches the number of matches seems to be incorrect. Try setting std:regex reg("(was)"); The number of matches evaluates to 2.
@samng1158
@samng1158 6 жыл бұрын
yeap, there is an error. not sure why might be the pattern
@NicoScholz90
@NicoScholz90 5 жыл бұрын
makes me wonder as well. Anybody got a clue what exactly goes wrong here?
@exodus8814
@exodus8814 6 жыл бұрын
Hey Derek! I have a suggestion, could you please think about doing compiler videos? That would be insane!
@derekbanas
@derekbanas 6 жыл бұрын
Compilers aren't really that complicated. You basically have to translate from one language to another. Making an optimized compiler is the hard part
@exodus8814
@exodus8814 6 жыл бұрын
Derek Banas thank you very much for response, sorry if I asked too many questions. :)
@marianacsinlove
@marianacsinlove 4 жыл бұрын
There's no need to declare de functions printmatches??
@Sebastian-qc3gw
@Sebastian-qc3gw 3 жыл бұрын
Hi, thanks for the tutorial, helped me a lot! I think reg7 should be "([^ ]\\..\\..\\.)". In this particular case it works, but if str7 was "F.B.I. I.R.S. CIA F.B.I." the output doesn't meet the expectations.
@jacktolmie1971
@jacktolmie1971 3 жыл бұрын
Thanks. I was wondering why I was getting warnings. I was looking through the comments for an answer to this exact issue :).
@vnm_8945
@vnm_8945 6 жыл бұрын
Can I ask how many tutorials will be added to complete this C++ tutorial and when this is going to happen, some estimation?
@derekbanas
@derekbanas 6 жыл бұрын
Sorry I don't know. I'll continue making tutorials until I feel I've covered most everything
@vnm_8945
@vnm_8945 6 жыл бұрын
Ok, thank you, I'm interested in linked list, I will watch all the videos, but I don't think it's covered. I'm learning something new in every video, thank you for the effort.
@cerrillotorrescarlosivan5442
@cerrillotorrescarlosivan5442 4 жыл бұрын
Muy buen video amigo, una duda, en el regex siempre se debe introducir la expresión a evaluar o hay alguna forma de hacer uso de regex pero que no se defina la expresión, si no que el usuario la introduzca?
@timothyleffel3186
@timothyleffel3186 6 жыл бұрын
thanks for making the internet a less icky place
@derekbanas
@derekbanas 6 жыл бұрын
I'm trying to do my best :)
@akagaming9431
@akagaming9431 6 жыл бұрын
Yeah, it's about goddamn time we have this tutorials haha :D I've been waiting for your C++ videos and it feels like ages, thanks for the tutorials Derek!
@derekbanas
@derekbanas 6 жыл бұрын
I'll do my best to get them out quicker. Work has been crazy lately. Maybe someday I can do this full time :)
@levhordiichuk6651
@levhordiichuk6651 5 жыл бұрын
Hi, you used ' \. ' in F.B.I. ex. and said that if i want to search ' . ' i must use ' \. ' and then in 'homework' you did not use ' \. ' . Can you explain why? Or you just made a mistake? Thanks. P.S. tutorial is really helpful.
@shinwarivideos3356
@shinwarivideos3356 4 жыл бұрын
sir I need this Odd length regular expression implementation in c++
@adamchalkley956
@adamchalkley956 6 жыл бұрын
I wouldn't call this a tutorial,because well it's not really,I would call it a refresher. You don't actually take time to explain whats going on instead you just write code assuming we already know what the function does,what it returns and how the functions you are using work.
@kedicat7
@kedicat7 5 жыл бұрын
Functions are explained here kzbin.info/www/bejne/baGvnZecj9qhgKs it is 10 -15 chapter before. (I am not Derek's friend or something but ...he explains it very well here. )
@JoeGlines-Automator
@JoeGlines-Automator 3 жыл бұрын
Regular Expressions rock! Thanks for this inspiring tutorial! I've made a few on it but enjoyed watching yours as well! :)
@derekbanas
@derekbanas 3 жыл бұрын
I'm very happy you liked it :) Thanks for taking the time to tell me
@larrybishop5139
@larrybishop5139 6 жыл бұрын
Hey Derek great video. I just have another question though. In your long c++ tutorial i saw you use some type of syntax. Is it better to use getline or just the regular cin?
@derekbanas
@derekbanas 6 жыл бұрын
Thank you :) Sometimes you have to use getline, but often they are interchangeable. For example we are receiving input here std::cout
@larrybishop5139
@larrybishop5139 6 жыл бұрын
Ok thank you.
@JustinK0
@JustinK0 4 жыл бұрын
Nice, Right out of ch 17.3 in the c+ Primer textbook that i read right before this video! haha
@junfengwei8877
@junfengwei8877 4 жыл бұрын
Hi,what is your ide? Vs code+clang
@_________________404
@_________________404 4 жыл бұрын
He's using netbeans. But I don't think it's the best IDE to use, he just uses it because he's on a Mac.
@crystyxn
@crystyxn 6 жыл бұрын
Hey great vids on c++. How long will this series be ? Please make one about making your own C++ library soon! Or if you know any resources you could redirect me to thanks
@derekbanas
@derekbanas 6 жыл бұрын
I'm not certain. I covered how to include outside files here kzbin.info/www/bejne/r6ixi3Sbl8x4kNk
@2271masoud
@2271masoud 6 жыл бұрын
Thanks for the tutorial Derek. I wish I could upload the photo I took of the screen with your name on top saying the best channels on KZbin. it happened in the biggest javascript meetup here in London. Thanks for all your efforts
@derekbanas
@derekbanas 6 жыл бұрын
Wow that is amazing!!! Thank you for telling me :) I've personally never met anyone that has watched my videos. It is always nice to hear that they have helped
@Omar-dd2lw
@Omar-dd2lw 6 жыл бұрын
yaaaaay a c++ video , love you
@derekbanas
@derekbanas 6 жыл бұрын
I'm glad you liked it :)
@neerajsingh769
@neerajsingh769 6 жыл бұрын
Please upload some video on advance internet technologies and web security based on java , servelets, ejb etc. Including xml...thanx
@brodypaterson6695
@brodypaterson6695 6 жыл бұрын
Hey Derek, I’ve been watching your videos for a while now, and I would like to know if you’d be open to making a how to make a desktop computer series. I hope you see this. Thanks your a great KZbinr and I love your videos.
@derekbanas
@derekbanas 6 жыл бұрын
Thank you for the nice compliment :) That isn't really my area of expertise and I'm also pretty cheap. I normally buy everything refurbished and buy old models. My current computer is 5 years old.
@brodypaterson6695
@brodypaterson6695 6 жыл бұрын
Derek Banas ah ok thanks for the response.
@HellHappens
@HellHappens 6 жыл бұрын
The internet was made to have such great information spread! Do you think you could cover MTAs on Linux? It is the most confusingly documented software I've ever seen. Exim would be nice but honestly I just want some help setting up custom emails
@derekbanas
@derekbanas 6 жыл бұрын
Thank you :) Do you want a mail server?
@HellHappens
@HellHappens 6 жыл бұрын
Well it's a long story. I have an odd boss who wanted to set up his own business, email server included. He basically said figure it out and I knew next to nothing about linux. He was then convinced Qmail was the way to go and for 5 months we tried messing with it to no avail via our ineptitude. We switched OS's three times from an older version of fedora, to the newest, to CentOs. then went with Exim. Got it half running, ran into an ssl certificate error and could only send emails to ourself. It has been quite the en devour and basically no tutorials exist that don't expect you to have a decent background in running things. I've always been avoidant when it comes to asking for things because I find it rude, but I would LOVE absolutely love an exim centos tutorial or any Mta/mail server tutorials. So Much love ~R
@Rashaadthegr8
@Rashaadthegr8 6 жыл бұрын
How do I use this in mac? Seems like the setup different then using virtual machine and visual studio.
@derekbanas
@derekbanas 6 жыл бұрын
I show how to install everything in this video kzbin.info/www/bejne/epLQpnhuibJmrtE
@exodus8814
@exodus8814 6 жыл бұрын
Hello again Derek, (leaving a new comment instead of a reply to insure that you get this), I've seen a reply of yours stating that you would do a simple graphics engine, my question is do you prepare/study before making such complicated topics? Or do you write them out of your head? I would love to be like this, is it possible to reach that point?
@derekbanas
@derekbanas 6 жыл бұрын
I'd research to make sure there aren't better ways then I currently know. I'm nothing special. Anything I do anyone else can do. I can't stress that enough.
@exodus8814
@exodus8814 6 жыл бұрын
Derek Banas Yes you are :) You're an inspiration and a very smart person Derek:) May God bless you and your family.
@derekbanas
@derekbanas 6 жыл бұрын
May God bless you and your family as well :)
@angadminhas7207
@angadminhas7207 6 жыл бұрын
Can you do one for swift 4?
@derekbanas
@derekbanas 6 жыл бұрын
I'll see what I can do
@AbhiRadhikaDas
@AbhiRadhikaDas 3 ай бұрын
Thanks man!
@kedicat7
@kedicat7 5 жыл бұрын
Thank you a lot, it is not easy to find good tutorials for c++ regex.
@derekbanas
@derekbanas 5 жыл бұрын
I'm happy I could help :)
@nikhiledu7556
@nikhiledu7556 6 жыл бұрын
I was little worried 😂 coz you didn't post for a while. Thanks✌️
@derekbanas
@derekbanas 6 жыл бұрын
Sorry for the wait. I was a little overwhelmed with work last week. I should be able to make a bunch of videos this week.
@theoathman8188
@theoathman8188 3 жыл бұрын
I have noticed that Regular Expressions are extremely slow and produce a massive assembly code. So if you can get away with it, please do.
@j055116
@j055116 5 жыл бұрын
Thank you very much! It helps me a lot.
@derekbanas
@derekbanas 5 жыл бұрын
I'm happy you found it useful 😁
@bruh-moment-21
@bruh-moment-21 5 жыл бұрын
very helpful! thank you!
@derekbanas
@derekbanas 5 жыл бұрын
Thank you :)
@joeflynt7480
@joeflynt7480 3 жыл бұрын
Okay so I dont mean this in a mean way so I hope if he ever reads this he doesnt take it that way but this guy sounds like the head pixie from fairly oddparents to me
@derekbanas
@derekbanas 3 жыл бұрын
That's funny :)
@akj7
@akj7 6 жыл бұрын
Thanks man.
@derekbanas
@derekbanas 6 жыл бұрын
Happy to help :)
@thebeginningk8944
@thebeginningk8944 6 жыл бұрын
Thank you very much
@derekbanas
@derekbanas 6 жыл бұрын
I'm very happy to be of help :)
@talha_coding_tutor
@talha_coding_tutor 4 ай бұрын
i used chat gpt for this std::regex singleOperandPattern(R"(^(\w+)\s+(-?\d+(\.\d+)?))"); std::regex doubleOperandPattern(R"(^(\w+)\s+(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?))"); can someone explain this to me !
@V1kToo
@V1kToo 3 жыл бұрын
Should have started with a very simple sentence instead of using a whole function.
@sayedrenaq7747
@sayedrenaq7747 3 ай бұрын
6:45
@ElMachoOpresor
@ElMachoOpresor 4 жыл бұрын
20:52
@ПашаХЗ-м8й
@ПашаХЗ-м8й 6 жыл бұрын
Это не все!
@shivamraj2649
@shivamraj2649 6 жыл бұрын
Finally
@derekbanas
@derekbanas 6 жыл бұрын
Sorry for the wait
@Alphabet_-_
@Alphabet_-_ 5 жыл бұрын
C++ Tutorial 20 : C++ Regex 2
15:14
Derek Banas
Рет қаралды 13 М.
Learn Regular Expressions In 20 Minutes
20:52
Web Dev Simplified
Рет қаралды 1,3 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
C++ Tutorial 15 : Smart Pointers & Polymorphic Templates
15:34
Derek Banas
Рет қаралды 37 М.
C++ 11 Library: Regular Expression 1
18:56
Bo Qian
Рет қаралды 54 М.
Regular Expressions (RegEx) in 100 Seconds
2:22
Fireship
Рет қаралды 599 М.
C++ Tutorial 11 : Polymorphism
18:48
Derek Banas
Рет қаралды 76 М.
C++ Tutorial 18 : Associative Containers & Container Adapters
21:06
C++ Tutorial 21 : C++ Regex 3
18:11
Derek Banas
Рет қаралды 16 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН