Regular Expressions in JavaScript - #1 REGEX ULTRA BASICS

preview_player
Показать описание
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:

Read more on MDN, it's the best resource:
Рекомендации по теме
Комментарии
Автор

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.

Crimsonaut
Автор

Thank you for this! Really appreciating the new devtips!

frederickbogdanoff
Автор

David is getting better and more confident doing these videos :)

mserrano
Автор

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

rossgeography
Автор

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.

MattKander
Автор

loved it. the most devtips-ish vid u guys have made so far

joebazooks
Автор

great video david, looking forward for more videos :)

Djzaamir
Автор

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!

BrianDriesenga
Автор

I needed this in my life so much right now, thank you so much!

gordonsmith
Автор

Yo dawg we heard you like backslashes so we escaped your backslashes WITH backslashes.

remoteworkboard
Автор

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!

bryansharpley
Автор

Good job! Even though I'm pretty familiar with regex I'm excited to watch the series :)

GameOver
Автор

Somehow there's a hole in my heart where Travis use to be :( not you're fault David, it's a great video.

seanrodriguez
Автор

You are Awesome buddy, it can't be explain better... Subscribed !!

lucasarregui
Автор

Thanks a lot! This was on my checklist to learn for my project! Can't wait for the next episode ;)

TheBBastard
Автор

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.

TomLeg
Автор

This is super useful :D thx for sharing your knowledge

miguelperezpal
Автор

have been doing form input validation for the past 3 days, even after watching the video and reading about regex, i still hate them

XavierGoncalves
Автор

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?

wingraptor
Автор

Any plans of making another series with mpj like the react one?

gunhound