Regular Expressions (Regex): All the Basics

  Рет қаралды 55,898

Luke Smith

Luke Smith

4 жыл бұрын

I go over how to get a lot out of just the fundamentals of regular expressions (regexes). We cover all the basics, but there is an even bigger world out there of possibilities I might cover in coming videos.
WEBSITE: lukesmith.xyz 🌐❓🔎
DONATE: lukesmith.xyz/donate 💰😎👌💯
OR affiliate links to things l use:
www.epik.com/?affid=we2ro7sa6 Get a cheap and reliable domain name with Epik.
www.vultr.com/?ref=8384069-6G Get a VPS and host a website or server for anything else.
brave.com/luk005 Get the Brave browser.
lbry.tv/$/invite/@Luke View my videos on LBRY.
www.coinbase.com/join/smith_5to1 Get crypto-rich on Coinbase.

Пікірлер: 217
@greyman1104
@greyman1104 4 жыл бұрын
"Crucifixion, well that's a nice thing as well." - Luke Smith, 2020
@internetfriendsimulation9156
@internetfriendsimulation9156 4 жыл бұрын
Luke confirmed for Longinus. Why else would he be so fluent in biblical languages?
@horndog2224
@horndog2224 4 жыл бұрын
@@internetfriendsimulation9156 hes redpilled
@robertoszek
@robertoszek 4 жыл бұрын
I feel like Luke's head is always cut off in his webcam view because his humongous chad brain wouldn't fit even if he went full screen.
@sch8836
@sch8836 4 жыл бұрын
It's a chest cam
@lovely-shrubbery8578
@lovely-shrubbery8578 4 жыл бұрын
@@sch8836 that's hot
@yoyojuninho6130
@yoyojuninho6130 4 жыл бұрын
He does that for the same reason he keeps wearing the sunglasses over his head.
@hershmysson
@hershmysson 3 жыл бұрын
@@yoyojuninho6130 he feels naked without them
@Jooohn64
@Jooohn64 Жыл бұрын
Vegapunk ???
4 жыл бұрын
2:06 grep stands for "global regular expression print". It is an ed command: g/re/p. Ed is the standard text editor.
@Jack-hd3ov
@Jack-hd3ov 4 жыл бұрын
was about to say this, +1
@musicamonarchy3062
@musicamonarchy3062 4 жыл бұрын
Ed is the standard text editor.
@francescominnocci
@francescominnocci 4 жыл бұрын
@@Jack-hd3ov same
@vN2w3Z59BM
@vN2w3Z59BM 4 жыл бұрын
kzbin.info/www/bejne/hIXJgKF9j7qNes0 that's just the backronym
@reralt
@reralt 4 жыл бұрын
Brian Kernighan himself said came from g/re/p
@pmester228
@pmester228 4 жыл бұрын
Finally, I needed a regex tutorial.
@sk8sbest
@sk8sbest 4 жыл бұрын
Sure u did
@mastercontrol5000
@mastercontrol5000 3 жыл бұрын
16:30 You can also use [A-z] to match any upper or lower case character, because uppercase comes before lowercase in the ASCII table. That syntax actually means "match any character in the ASCII table between these two characters".
@bahathir_
@bahathir_ 4 жыл бұрын
I use grep to cheat a text based game called 'hangman'. I use GNU grep "-w' option to word matching.. Example: $ grep -w 'v.ir.s' /path/to/dictionary/file Thank you.
@MarechalMaudutor
@MarechalMaudutor 4 жыл бұрын
thanks for the information bro. الله يبارك فيك
@user-gz7rw8bs3v
@user-gz7rw8bs3v 3 жыл бұрын
...or for crosswords.
@simozonelayer
@simozonelayer 4 жыл бұрын
"I want a period" - Luke Smith, 2020
@migtrewornan8085
@migtrewornan8085 4 жыл бұрын
"\+" is nothing to do with the shell - it's because grep uses Basic Regular Expressions which doesn't include "+" as a metacharacter. If you use egrep (which uses Extended Regular Expressions) you won't need the "\".
@minhajsixbyte
@minhajsixbyte 4 жыл бұрын
@@juxuanu egrep is a thing. search it.
@minhajsixbyte
@minhajsixbyte 4 жыл бұрын
@@juxuanu No, sorry, misunderstanding, i thought you said "as far as i know its grep -E, not egrep"
@sk8sbest
@sk8sbest 4 жыл бұрын
@@minhajsixbyte egrep is deprecated
@minhajsixbyte
@minhajsixbyte 4 жыл бұрын
@@sk8sbest oh. i know very little about these things actually. but why is this depricated btw?
@minhajsixbyte
@minhajsixbyte 4 жыл бұрын
@@sk8sbest oh thanks I have searched and got the answer!
@jonathanwarner1844
@jonathanwarner1844 4 жыл бұрын
The problem for me with regular expressions is the learning curve with using them efficiently, and since I only need to use them infrequently, I never get familiar enough with their use, to use them to their best advantage. If I were using them all the time, I would not have to keep starting from scratch, learning how to use them.
@StickeeAce
@StickeeAce 4 жыл бұрын
Your channel has taught me more useful knowledge than college did
@ruhnet
@ruhnet 4 жыл бұрын
Great video! BTW “asdf./“ is actually a valid URL since all domain names technically end in a period after the TLD. Most software infers the period if it isn’t specified, which is usually the case. Specifying the period at the end is actually the more correct format. So for example “google.com./search” is valid and should work in any software that accepts a URL.
@davidbanhos7308
@davidbanhos7308 4 жыл бұрын
15 years working as a developer, at last someone made regular expression easy! I finally understood! Thanks Luke!
@NikoxD93
@NikoxD93 4 жыл бұрын
7:32 listen carefully when he says "spool", he makes the perfect old Minecraft fall damage sound! Wizardry
@cj00785
@cj00785 4 жыл бұрын
I swear I haven't really understood regex until now. Thanks for sharing your knowledge
@hammerheadcorvette4
@hammerheadcorvette4 4 жыл бұрын
Luke could do a 10 video series on Regex and still not scratch the surface. I encourage this content !!!
@kirk0831
@kirk0831 4 жыл бұрын
I really like the way you explain Linux stuff!!
@wepranaga
@wepranaga 4 жыл бұрын
thank you so much, this is so useful and in depth. teach you basically 90% there I literally sit through the whole thing effortlessly. great video
@haythamadnan3465
@haythamadnan3465 Жыл бұрын
Thank you Luke for this wonderful video.
@mansourq6512
@mansourq6512 4 жыл бұрын
Words can’t describe how much I’m grateful for what you did
@sayanghosh6996
@sayanghosh6996 4 жыл бұрын
I was literally looking up several articles about regex today! This is perfect timing.
@TheZMDX
@TheZMDX 4 жыл бұрын
To be honest this is one of the best videos on your channel Luke. Short and informative, thank you.
@TheDrakkens
@TheDrakkens 4 жыл бұрын
Just in time, I needed this for writing my first script, thanks Luke!
@humanbeing_
@humanbeing_ 2 жыл бұрын
Thank you for this Luke! This is a HUGE help for me 👍
@parthhanda6828
@parthhanda6828 4 жыл бұрын
I was recently thinking about starting to learn regex and this was really helpful as an introduction. Thank you.
@donihalim3239
@donihalim3239 4 жыл бұрын
Thank you Luke!
@PROGamersf36
@PROGamersf36 2 жыл бұрын
Thank you ! It is a great lesson!!!
@mightsnipe
@mightsnipe 4 жыл бұрын
Thanks Luke, super helpful! Cheers
@rochelouis2494
@rochelouis2494 Жыл бұрын
super super, gracias por compartirnos este video. muy ilustrativo.
@patrickprucha5522
@patrickprucha5522 8 ай бұрын
Thanks Luke. Good video!
@JurajOravecSGOrava
@JurajOravecSGOrava 4 жыл бұрын
Luke shows us magic.
@RishabhRD
@RishabhRD 4 жыл бұрын
Vim diesel
@apoorv9492
@apoorv9492 4 жыл бұрын
thank you for video, i recently have been trying out DWM with dwmblocks, and wanting to write scripts for the statusbar, this was very helpful. im finding shell scripting very interesting and fun. i sure want to learn more. hope there's a follow up advanced video.
@hemanthakumar.h.n.4382
@hemanthakumar.h.n.4382 2 жыл бұрын
Very useful :) thank you!
@GeneralHazerd
@GeneralHazerd 4 жыл бұрын
@Luke Smith keep up the good work 👍
@FuzanToko
@FuzanToko 4 жыл бұрын
Thanks for sharing
@CrawlingChaos666
@CrawlingChaos666 Жыл бұрын
The Word of Luke have Power...
@deagle-zlt
@deagle-zlt 4 жыл бұрын
Спасибо! Хорошо всё объяснил. Хорошее видео
@eporeon
@eporeon 4 жыл бұрын
luke kept his knee in the face cam the entire time what a power move
@simozonelayer
@simozonelayer 4 жыл бұрын
Really helpful.
@xtdycxtfuv9353
@xtdycxtfuv9353 4 жыл бұрын
this was a useful video. ty luke. I have to admit the oomer convention made me laugh and was very meta
@RiteshKumar-lh1xn
@RiteshKumar-lh1xn 4 жыл бұрын
Thank you very much for this. Please make advanced video on this too if you get time.
@albarshini490
@albarshini490 4 жыл бұрын
I was going to Email you to ask you to do this video, Thank you Luke very cool.
@TheGaridi2
@TheGaridi2 4 жыл бұрын
I wa implementing search functionality on my web app and regexp is essential thanks for this crash course
@kelvinmuli5420
@kelvinmuli5420 4 жыл бұрын
Love regex so much..
@diegoestrada35
@diegoestrada35 4 жыл бұрын
I found this really usefull
@evmanbutts
@evmanbutts 4 жыл бұрын
Just bricked my Grub while installing Debian to play around and spent a while getting it back. Let's keep that learning train Rollin!
@andreyseliverstov3134
@andreyseliverstov3134 4 жыл бұрын
Suggestion for the future video: full-text instant search in a local 2 TB archive of textbooks and articles (PDF + DJVU). Using regex, of course.
@mfrederikson
@mfrederikson 4 жыл бұрын
insane
@jcc1199
@jcc1199 4 жыл бұрын
now that we've found all instances of a certain thing in a text file, can you make a video on deleting, moving, replacing, etc. -- putting to use the output we've gotten here? thanks a lot. chad-like teaching content as usual
@kyu9649
@kyu9649 4 жыл бұрын
Good video. Maybe make a part 2 where you go over grouping and such, as it is also quiet important :P
@arissk_
@arissk_ 4 жыл бұрын
Nice work. I like your videos on general command line tools. Can I suggest a presentation on sed or awk? I know these tools may require longer videos but I m sure you can manage it
@horndog2224
@horndog2224 4 жыл бұрын
This actually is just in time for my sys admin class at uni over the summer, thanks luke!
@Pabloparsil
@Pabloparsil 3 жыл бұрын
I think newbies out there would also like to know that and \t also have special meanings: end of line and tab respectively. I'm not sure if that works with grep but it does work with other tools like python. I use them all the time
@abrokenlink_
@abrokenlink_ 4 жыл бұрын
Yo I have no idea what I’m watching but it sounds cool.
@oleksiynehlyadyuk8123
@oleksiynehlyadyuk8123 4 жыл бұрын
wow that's a regex tutorial now.. can't wait more deeper examples
@hp8246
@hp8246 4 жыл бұрын
Great video. Thanks for sharing these fundamentals of regular expressions. Do these basics work on Vim? Thanks again.
@pward17
@pward17 4 жыл бұрын
No bloat on these pups. I like that.
@escravovoluntario6698
@escravovoluntario6698 4 жыл бұрын
Regex is awesome.
@JasonDeBoltGoogle
@JasonDeBoltGoogle 4 жыл бұрын
Luke, have you considered creating videos on cloud? You appear to be a systems thinker and I’d bet that you can teach cloud technologies pretty well.
@DavidJBurbridge
@DavidJBurbridge 4 жыл бұрын
Me thinking yesterday: I should get around to learning regex for better grep/sed/awk etc Then you put this up. Cheers uncle Luke
@reverseila4363
@reverseila4363 4 жыл бұрын
Tnx for regx! Could you make a video on git and show us how you use it on your daily basis?
@cpubug
@cpubug 2 ай бұрын
thnx
@RaivoDoc
@RaivoDoc 4 жыл бұрын
This will actually land me a better job.. wow.
@Viken43
@Viken43 4 жыл бұрын
Luke Smith has saved Linux overnight, invented time travel, an alter ego and global warming.... and of course LARBS ;-)
@mersno
@mersno 4 жыл бұрын
I consider myself decent at bash but your videos always provide value, thanks boomer
@osamaadil231
@osamaadil231 4 жыл бұрын
Will it help me find a soulmate?
@JurajOravecSGOrava
@JurajOravecSGOrava 4 жыл бұрын
yes
@FishKungfu
@FishKungfu 4 жыл бұрын
@@JurajOravecSGOrava y y y y y y y y y y y ...
@BCDeshiG
@BCDeshiG 4 жыл бұрын
9:20 Finally, I can call someone every single oomer at once
@marciomaiajr
@marciomaiajr 4 жыл бұрын
Congrats on reaching 90k subs Luke. Waiting for the 100k special video where you install FreeBSD on a Thinkpad X60.
@auronkardek
@auronkardek 4 жыл бұрын
FINALLY
@zoop2174
@zoop2174 4 жыл бұрын
If you decide to make a more advanced tutorial definitely include lookahead and lookbehind as I use them all the time.
@spartan1o5
@spartan1o5 4 жыл бұрын
doing gods work! any cool projects like the corona project you had before?
@phiasch
@phiasch 4 жыл бұрын
How are you quickly saving the 'note' file? I know ZZ is similar to :wq, but what's the similar command to :w? Where would I find the docs to read about commands like ZZ?
@magetaaaaaa
@magetaaaaaa 4 жыл бұрын
Regular expressions is one of those things I need once in a while, wind up spending a bunch of time creating something that looks like I hit my head on the keyboard, then forget how I did it months later. It can be simple, but it can also start to get long and tiresome if the requirement is more complicated, like matching any valid IP address "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
@evannoynaert
@evannoynaert 4 жыл бұрын
Is there a reason you were using double quotes instead of single quotes? I would be more inclined to use single quotes with grep and egrep to avoid accidental expansion problems. Generally I only use doubles when I know that I really want expansion. Here is an example to demonstrate the difference. Add two lines to your rt file: The first is the sentence "Navigate to your $HOME directory." Then add the absolute address of your home directory to the file. You could do this with the command "echo $HOME >> rt" Now the results of grep "$HOME" rt and grep '$HOME' rt give very different results. Also, I tend to use either egrep or grep -E instead of just plain grep. This is in part because I cut my teeth on Regular Expressions in Perl, and egrep is closer to the Perl that I learned first. It is also considerably more powerful.
@antadhg
@antadhg 5 ай бұрын
instead of [0-9] for all digits you can use \d, similarly for any non-digits you can use \D
@tacitus_
@tacitus_ 4 жыл бұрын
Hey Luke, sorry if this is too personal, but I noticed that you've started to display a lisp. Did you recently get Invisalign braces (or has the social isolation lowered your pronunciation level)? I had braces put on in my mid 20s and they made me a little lispy too
@ryukthegodofdeath8063
@ryukthegodofdeath8063 4 жыл бұрын
Awesome. Next awk?
@veryown8084
@veryown8084 4 жыл бұрын
5:04 yeah it's from the regural expressions of formal languages (more specifically Regural languages which are equivalent of L3 languages, those that can be generated form a right-linear grammar) where x* means {x}* so basically (x^0, x^1, x^2, ... ) x^0 is epsilon or lambda (also known as the empty word, a word of 0 letters) and x^1=x, x^2=xx, x^3=xxx and so on
@veryown8084
@veryown8084 4 жыл бұрын
5:28 {x}^+ is basically the same as {x}^* but without the epsilon/lamda, so it's (x^1, x^2, x^3...) As you can see this have something to do with Math more specifically with monoids. More infos here: www.ncbi.nlm.nih.gov/pmc/articles/PMC3367686/ en.wikipedia.org/wiki/Regular_grammar
@victorprokop2240
@victorprokop2240 4 жыл бұрын
hey luke How can I integrate uganda.txt to my neovim i reaaally like it
@DeepakRajan
@DeepakRajan 4 жыл бұрын
Please keep making videso
@ianpan0102
@ianpan0102 4 жыл бұрын
I clicked on this video because from the thumbnail I thought Luke was naked (his T-shirt colour).
@mgetommy
@mgetommy 4 жыл бұрын
epic swag
@peterjansen4826
@peterjansen4826 4 жыл бұрын
boomer, zoomer, doomer, coomer. I can' t keep up anymore, I must be gbetting old. Apparently I am a boomer now according to the zoomers even though I never was a boomer before.
@morzinbo
@morzinbo 3 жыл бұрын
boomer is a mindset as well as a generation of people that destroyed the USA
@tato-chip7612
@tato-chip7612 4 жыл бұрын
luke how did your setup handle multiple languages for your linguist work?
@cocoapuffs5299
@cocoapuffs5299 4 жыл бұрын
i'm also interested in this, as i use arabic and spanish.
@kubre
@kubre 4 жыл бұрын
n+1 th video about regex im watching
@FyahBurn95
@FyahBurn95 4 жыл бұрын
Good introduction with good examples! To throw something useful into it, don't you find weird you need to escape '+' but not '*'? And '*' is a (famous) shell expansion, but '+' is not! Also, if this was the case, it would be solved by the usage of double quotes you do, which avoids expanding anything but the dollar sign (for variables), or by switching to single quotes, which don't allow for any shell processing. The actual thing happening is that grep uses default regular expressions and the plus sign is from extended regular expressions, which grep understands but only if they are escaped. To use extended regexps without the need for escaping their metacharacters, try egrep or grep -E.
@ganainm01
@ganainm01 4 жыл бұрын
The "+" was not part of the original set of special characters; in fact, "a\+" (or "a+" with EREs) is just an alternative way to write "aa*".
@anishpoudel5383
@anishpoudel5383 4 жыл бұрын
Luke could you make video about history of linux terminal editor ...
@pichass9337
@pichass9337 4 жыл бұрын
You read my fucking mind
@iLiokardo
@iLiokardo 4 жыл бұрын
to match any letter, lower case or upper, i think you can do [a-Z]. much better.
@mrkvaccc
@mrkvaccc 4 жыл бұрын
Luke before: Searches for Jesus Luke now: "Crucifixion, well that's a nice thing as well"
@hofrreeze
@hofrreeze 4 жыл бұрын
I never expected that GG Allin would lecture me about regex someday.
@DigitalMetal
@DigitalMetal 4 жыл бұрын
"[a-Z]" should work the same as "[A-Za-z]". Although there might be a difference I'm unaware of.
@FyahBurn95
@FyahBurn95 4 жыл бұрын
It matches by the actual code of the characters, and there are characters between z and A, so it would match all the letters plus other stuff.
@elandje
@elandje 4 жыл бұрын
It will probably behave in an unexpected way, because the upper case letters come BEFORE the lower case letters in ASCII...
@FyahBurn95
@FyahBurn95 4 жыл бұрын
@@elandje I was going to answer this, but if you try grep with [a-Z] it works, but if you do it with [A-z] it says "invalid range end". What??
@elandje
@elandje 4 жыл бұрын
@@FyahBurn95 It is like I said, 'Z' comes before 'a' therefore it is invalid. [A-z] works, but includes a few non-letters, like [, |, ] and @. Search online for ASCII table.
@FyahBurn95
@FyahBurn95 4 жыл бұрын
@@elandje Have you tried it? [A-z] does not work with grep for me, but [a-Z] does. I know what the ASCII table is and the fact that A-Z comes before a-z, and also that UTF-8 is an extension of ASCII, which is what matters unless you actually work with ASCII files.
@zacharycarbon4312
@zacharycarbon4312 4 жыл бұрын
I've yet to see a more digestible explanation of regex. And I have seen many.
@axpanos
@axpanos 4 жыл бұрын
When is the jagex tutorial coming?
@BarraIhsan
@BarraIhsan 3 жыл бұрын
Or you can use \w to match letter and \W to match non letter And \d to match digit and \D to match non digit CMIIW
@thefantasicm_2407
@thefantasicm_2407 4 жыл бұрын
Will you be able to design a regular expression which matches exactly the words a^n.b^n (a random number of 'a' followed by the same number of 'b') ? ;-)
@magetaaaaaa
@magetaaaaaa 4 жыл бұрын
So the criteria is that it must match instances of ab where the number of a's and b's are equal? So ab or aabb would match but abb or aaaaabb would not match?
@thefantasicm_2407
@thefantasicm_2407 4 жыл бұрын
@@magetaaaaaa yes this is the criteria :-)
@magetaaaaaa
@magetaaaaaa 4 жыл бұрын
@@thefantasicm_2407 Hmmmm, I'm not a regex guru by any means but I feel like there would almost have to be something out of regex to do the analysis? I feel like trying to come up with a solution now.
@thefantasicm_2407
@thefantasicm_2407 4 жыл бұрын
@@magetaaaaaa This is a tricky question : the answer is that it is impossible to recognize this language with regular expressions, sorry :-). This is related to the Kleene theorem. Look for Pumping lemma (regular languages) to understand why.
@magetaaaaaa
@magetaaaaaa 4 жыл бұрын
@@thefantasicm_2407 Hmmmm, maybe something like this would do the trick with Python. import re file = open("textfile.txt", "r") for line in file: a = line.count('a') b = line.count('b') if re.match("^a+b+$", line): if a == b: print(line)
@musicamonarchy3062
@musicamonarchy3062 4 жыл бұрын
Ed is the standard text editor
@normanpedersen5454
@normanpedersen5454 4 жыл бұрын
My life: This is a learning exercise. Who cares.
@biehdc
@biehdc 4 жыл бұрын
Finally a regex to human translator
@elclippo4182
@elclippo4182 4 жыл бұрын
17:35 How to validate an email address using a regular expression? stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression
@ordici_
@ordici_ 4 жыл бұрын
how do you make grep only print the text in red?
@ganainm01
@ganainm01 4 жыл бұрын
That's a GNU grep thing with the --color option.
Regular Expressions - Computerphile
17:19
Computerphile
Рет қаралды 239 М.
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 36 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
Кушать Хочу
Рет қаралды 2,9 МЛН
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 14 МЛН
Using `sed` and Regular Expressions (Unix/Linux command line)
14:56
Vim Tips You Probably Never Heard of
12:11
Luke Smith
Рет қаралды 112 М.
Regular Expressions (Regex) Tutorial: How to Match Any Pattern of Text
37:55
Become a shell wizard in ~12 mins
12:25
CODE IS EVERYTHING
Рет қаралды 218 М.
How Do Regular Expressions Really Work?
29:10
Low Byte Productions
Рет қаралды 27 М.
Why am I so Anti-Video Gaymes?
9:52
Luke Smith
Рет қаралды 155 М.
ТОП-5 культовых телефонов‼️
1:00
Pedant.ru
Рет қаралды 18 М.
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 2,3 МЛН
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 42 МЛН
wireless switch without wires part 6
0:49
DailyTech
Рет қаралды 4,7 МЛН
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 24 МЛН