2.5: Regular Expressions: Back References – Programming with Text
- December 21, 2023
- Posted by: MainInstructor
- Category: JavaScript Regular Expressions
![*](https://i0.wp.com/allprowebdesigns.com/wp-content/uploads/2023/12/1703196879_hqdefault.jpg?resize=480%2C360&ssl=1)
Video Title: 2.5: Regular Expressions: Back References – Programming with Text
Okay here’s another regular expressions video and in this video I’m going to show you how to use a back reference in a regular expression so this is going to make use of capturing groups which I covered in the previous video but what I didn’t do in the previous video is I
Only showed you how to use a capturing group in a fine and replace operation where the syntax is dollar side one for referring to group number one but what if I want to refer to group number one in the regular expression itself in this case I use backslash one so a classic
Scenario for this which is taken from Jeffrey Friedel’s mastering regular expressions book which I highly recommend is searching for double words what I mean by that is o is is appears twice in a row double double appears twice in a row not not appear story surround why why what if I want to
Search anytime two words appear in a row so let’s figure out how I would do this so first I can look for just any sequence of you know at one or more word characters in a row and you can see I’ve matched all of the words now I could
Capture that alright I could say one or more word characters in a row followed by what some sort of white space right backslash s I don’t know if you can see this I’m gonna zoom in here to try to help you see it better backslash s followed by what backslash
One look at this I’m saying match any number of word characters in a row followed by and capture it as Group one followed by space and hey the thing that you captured is Group one not any word character in a row the specific actual sequence of word characters you match
That again so look at this it doesn’t get you two words in a row right you’re no I’m not matching some text or somewhere or am typing I’m only matching when the the exact same word is followed by the exact same word rainbow rainbow unicorn Yuriko not not double double now
There is some weird stuff going on here for example look here it matched is is this is and it matched s some with s and s so one thing I need to do here is have word boundaries as part of this as well so for example if I say okay well
There’s got to be a word boundary here and then there’s also got to be a word boundary here then now I’m only getting is is text X double double not not rainbow rainbow unicorn unicorn now notice again this is how regular expressions work it matched III but
Didn’t match this I I and again there’s some ways around that which you know I’ll leave that for another time but you can see this is a very powerful thing that you can do that you can actually refer to something that was matched in a regular expression by using
Backslash 1 and this sort of double words exercise a double words example I think is a good one to look at okay thanks hey this was a short one I have a camera went off forever typing okay so thanks for watching this one and after this video you have now
Reached the point I think let me say a couple things there’s more to regular expressions than when I’ve covered in this sort of introduction I think for videos so far I’ve kind of going through position meta characters single character quantifiers character classes call alternation capturing groups back references cetera there’s bored there’s
Something called look ahead and look behind there’s probably more meta characters that I miss there’s a lot of nuance it’s different in different programming languages I can’t get to everything here I’m sure I’ve missed stuff I’ll come back maybe do more but I want to move now to actually looking at
How you execute regular expressions in the JavaScript programming language itself with the functions test search match exact split replace and then do some a coding challenge around rebbe expression so in the next videos you’ll start to see regular expressions in JavaScript itself
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
goood bro
Sir, Thank you so much for the video, request you to tell me what is the interface that you are using to show us these examples.
What's the reason why the regular expression did not capture the third I? Is it because it reads the first match from left to right only?
2:41
"/b(w+)s+1(?:s+1)?b/g" will solve the problem I guess.
1) (?:) – non capturing group
2) s+ – one ore more times whitespace
3) (?:)? – making non capturing group optional
Wow That's Fun! Seriously, I enjoy the way you teach this. Thank you.
How to match those 3 I's !!??
So useful, thanks dude.
this was amazing.
Thanks! Really clear!
b(w+)(s1)+b Can anyone tell about this pattern?
I can write simple regex but my head aches with long and complex regex. Can you explain what is the useless part in this regex. I used it for url validation with subdomains and wildcard. /^(https://)?(www.)?(*.)?(([a-z0-9]+[-_]?[a-zA-Z0-9]+).?)*.[a-z]{2,11}(#?/?*?.?[a-zA-Z0-9]+)*(/*)?/?(?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/
Dude, how are more people not liking these videos! Big man videos, making this potentially confusing topic fun! Thanks a lot
I look up to you.
nice teaching style yaar
Question: I have the following regex and text and i would like to match all doubles. However when I try to match them all it skips the 2nd line. How come? Note i am working in bash via mac terminal.
what flags should i used besides -o and -i
([a-z]+) +1
Paris in the the spring.
The theoretical viewpoint is of little value here.
I view the theoretical viewpoint as being of little value here.
I think that that is often overdone.
This sentence contains contains a doubled word or two two.
Fear fear is a fearful thing.
Writing successful programs requires that the the programmer fully understands the
problem to be solved.
Thanks. These 5 videos on RegEx were exactly what I was looking for. You should consider doing a full series on this to an advance standard.
Genius lessons! Thank you! Without your tutorials I am afraid I will never understand those gibberish regex characters!
I am so glad I discovered this channel! Pieces are slowly falling into place now. I first came here searching for lookaheads in JS but I can't find a good lesson about them. Can anyone point me in the right direction? I Hope Daniel covers them in the following videos of this series =)
Great!
Yep. I definitely love regex now.
so awesome explanation )
Hey, brilliant videos for RE and Processing. Really interested in a solution to the triple I problem you mention around the 4 minute mark. How would you solve this? I feel there is some deeper understanding of how regular expressions search that is keeping me from solving this. Thank you!!!
Crazy
thank you. At the begining I was not sure if I like you or not, but after a few videos I'm sure I do 😀 Videos are good because you are actually doing this as live recording, you are making mistakes, you are not boring, and I no longer hate regex thanks to you 😀 You made my life easier.
Enthusiastic, goofy, nerdy, geek, kinda weird, and cute? I found the best programming channel in existence!
Subscribed
Thank you soooooooooooo much, Mr. Coding Train!!!!! I have struggled with Regex for a long time but with just the first 5 videos of Regex Theory. You make my life shine!!!!
In my opinion, this is the best tutorial series on regex on youtube. Thank a lot!
These were so well done! (Don't tell my teacher I didn't really understand anything he was saying and then came here after class instead. 😂)
You make things simple and fun
Your explanation of regular expressions is awesome.
i was looking all your expression videos just for this problem solution…amazing
Excellent videos on regex among the one that I found on youtube
wish I found your videos earlier! Great content bud keep teaching!
Remember: in JavaScript you should type $& instead of $0
(bw+b)(s1){1,2}