A regular expression (or regex) is way to find strings within strings. It’s small code that when applied to a string, will give other strings – either the whole string or parts of the string. This video gives you the ULTRA BASICS of REGEX.
Regexes most common use cases are:
What can we use them for?
1. Validation
If something is formatted correctly. Like verifying if someone has inputted the correct things in a form like an email address or a postal code
2.Extraction
Extract parts of a string that we would like to use. Say find how many times someone wrote “david” in a text.
Replacement
Find all parts of the string with “david” and replace them with something else like “devtips”.
You will learn:
– creating regex in two ways in JavaScript: slash notation or with the constructor new RegExp()
– escaping the special characters
– the special characters and how they work: ^, $, *, +, [a-z], [0-9], w, d for example
Companion code used in the episode
Or try one of these tools to experiment with regexes. They all do basically the same, it’s just a matter of taste:
https://www.regexpal.com/
https://www.regexpal.com/
https://regex101.com/
Read more on MDN, it’s the best resource:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Original source
42 responses to “Regular Expressions in JavaScript – #1 REGEX ULTRA BASICS”
You Are Awesome!
This is hardly "Ultra Basics".
Awesomw Guide! Thank you!!!
You are Awesome buddy, it can't be explain better… Subscribed !!
Sorry but I found this super confusing, I didn't understand what the special characters meant or why you were using them, opening and starting a string. Would have liked a bit more context as to the structure/grammar of a regex expression.
Great video, Regex is a lot simpler than it looks. Although I still don't understand why a* ([ ][aaaa]) and a? ([ ]b[a]b[a]) match an empty character at the beginning, when there's no empty character there?
Wow, thank you!!
I'm fairly new to javascript and was wondering what the ${phoneNumber} is ${isValidNumber} type notation is called. See around 10:37 in the video?
Yo dawg we heard you like backslashes so we escaped your backslashes WITH backslashes.
I have needed this forever – I have the O'Reilly books but never had the motivation to just get started – an intro is much needed – THANKS DevTips Dudes
When I tried "end$" REGEX on "match end at the end" in ur REGEX code codepen site , it is highlighting "match 'end' at the end" instead of "match end at the 'end' ".
How can I verify "end" at the last one is present?
loved it. the most devtips-ish vid u guys have made so far
Thanks David amazing
Looking forward to the next video David!
Could you please do a tutorial about aria and aria-hidden
Hey, can ya'll do video on visual studio code and it's packages.
Hi i have took many course online for the past few month to learn web development. from my learning experience i realise that there are lots of great courses out there but that almost all of them does the same things. when i finish all these courses i felt that i am ready and i have the basic in skills, i try to begin my preparation of building projects and portfolio but i was overwhelm by all this design and effects from this websites that people are able to do, i think there are lots of cool effects there and maybe i suggest u can took some inspiration from making tutorial from this web site on your channel? https://www.cssdesignawards.com
This is super useful π thx for sharing your knowledge
Great explanation David!
Nice to see this topic covered many explanations of regex are go to stack overflow and get a snippet… there you go regex lol
Thanks for giving a real explanation of the how and why!
Change speed to 1.25
Used to be, once upon a time, everyone used the regex library from Henry Spencer, of U Toronto. The Perl programming language expanded what regex could do, so nowadays, languages either import the Perl regex library or re-implement it .. or a subset of it.
So it you find regexp powerful, learn Perl and find out what more you can do with regular and not quite regular expressions.
Cool vid
Yay!
thanks very match
Fantastic idea for a new series. My brother has developed a reputation as being a REGEX master. Developers are always asking his advice with them. They are super useful.
David is getting better and more confident doing these videos π
Somehow there's a hole in my heart where Travis use to be π not you're fault David, it's a great video.
Very nice explanation. I knew someday I would want to add a deeper understanding of RegExp. Glad to hear that this is part of a series. Really want to nail this down. Thanks David!
I needed this in my life so much right now, thank you so much!
Enjoyable Video, hope you will feature non-greedy operators for somthing like
/<.*?>/ matches "<foo>" in "<foo> <bar>", whereas /<.*>/ matches "<foo> <bar>.
As for feedback:
I really liked the react js series, something similar would be awesome like already suggested.
1) start to finish web app
2) framework like polymer progressive web app
Using codepen is awesome, it is so easy revisit the given example
π
The black hole that was regex has been filled for me! Thanks David
Thanks a lot! This was on my checklist to learn for my project! Can't wait for the next episode π
Good job! Even though I'm pretty familiar with regex I'm excited to watch the series π
have been doing form input validation for the past 3 days, even after watching the video and reading about regex, i still hate them
makes more sense now. Thanks π
you should try this https://regex101.com/
i lovei ittt πππ
great video david, looking forward for more videos π
Thank you for this! Really appreciating the new devtips!
We want Travis back
Any plans of making another series with mpj like the react one?
Great video!