Using regular expressions in JavaScript

preview_player
Показать описание
Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

What is a Regular Expression
A regular expression is a sequence of characters that forms a search pattern.

Let us understand the use of regular expressions with an example. The following strings contain words and numbers. From the string we want to extract all the numbers. Bsically the program should work with any string.

Mark-9 Tim-890 Sam-10 Sara-9902
Result : 9, 890, 10, 9902

908ABC12XYZ34
Result : 908, 12, 34

$1 $2 $901 ABC(100)
Result : 1, 2, 901, 100

Here is what we want the page to do
1. User enters the string in the first textbox
2. When "Process String" button is clicked, the numbers should be extracted from the string and displayed in the text area element.

It will be very complex and error prone if we have to achieve this without using regular expressions.

[input type="text" id="txtBox" style="width:250px" /]
[br /][br /]
[input type="button" value="Process String" onclick="processString()" style="width:250px" /]
[br /][br /]
[textarea id="txtArea" rows="4" cols="30"][/textarea]
[script type="text/javascript"]
function processString()
{
// Clear the textarea element
// Retrieve the user intput from the textbox
// Regular expression should be in 2 forward slashes //
// Letter g at the end of the regular expression performs a global match
// match() method returns all substrings that match the given regular expression

if (result != null) {
// Add the retrieved numbers to the textarea element
}
}
}
[/script]
Рекомендации по теме
Комментарии
Автор

You have the best tutorials on internet, by far. I am so thankful to you, I got my first job due to your SQL tutorials, second job due to your C# tutorials and now I'm using this on my third job. Thank you very much sir.

krutomjer
Автор

Just the explanation i was looking for. Thanks! You earned an extra subscriber :-)

DANJUMA
Автор

Hello from South Africa. Your videos are excellent. Better than any video tutorials I have watched. I love that you build up your explanation from start to finish. Thank you very much for your contributions.

fabianmadurai
Автор

You helped me get through part of project I was stuck on. Thanks!

sunmustbedestroyed
Автор

awesome job mate. set me upon the right path for my javascript validation

Dynamic
Автор

Omg thank you ! so clear and so helpful, i can already tell i will be watching all of your videos lol

Jethorus
Автор

one of the best tutorial on regular expression. god bless you.

sourabhkulkarni
Автор

I wish there were more instructors like you on youtube dear sir. All my respect!

zenlogie
Автор

This was very helpful.
Thank You for sharing your knowledge.

samdavepollard
Автор

Excellent series...very helpful! Thanks!

garrettbaker
Автор

Amazing tutorial sir!!! Thank you very much for your help!!!

elkhanhamet
Автор

Thanks, man.
As always, great stuff!

jaxparrow
Автор

Thank you..
but can you make video for regular expression, to make a good understand of it.

davidespada
Автор

This is great, I always get confused by regular expressions!

ConaxHateGG
Автор

Thank you for your video! You rule! Thumps up!

pancakesmister
Автор

Awesome to have php vedio in your chanel...!

shaikarshad
Автор

is there a cheat sheet of all reg exp?

getpwnd
Автор

you're the best in the world!! :D

FernandoDiaz-lybr
Автор

Thanks for posting! This answered a question I've been researching.

cynthiamanor
Автор

Why would you use XHTML 1.0 instead of HTML5 for this tutorial :/ . I don't understand anything because of that.

yeahforsurebro