JavaScript RegExp Object & RegExp Methods | JavaScript Regular Expressions - JavaScript Tutorial 88

preview_player
Показать описание
Notes for You:: JavaScript RegExp Object & RegExp Methods

What is RegExp:
- RegExp is a built-in object, used to define a search pattern (or regular expression), which can be used to make a wide variety of tests on a given string.

Application of Regular Expressions:
- Search for a word(s) in a given string
- Find & replace a word(s) in a given string
- Perform data validations etc. etc.

1. Defining regular expression using RegExp object constructor notation:

Syntax:
var variableName = new RegExp("search pattern", ["flags"] ) ;

Ex: phone number validation
var pattern = new RegExp("^[0-9]{10}$") ;

2. Defining regular expression using RegExp literal notation:

Syntax:
var variableName = /search pattern/ [flags] ;

Ex: phone number validation
var pattern = /^[0-9]{10}$/;

JavaScript RegExp Methods:

test() Method:
- is used to test is there match or no match between regular expression and the given string.
- If there is a match then it returns true otherwise returns false.

Syntax

Ex:
var phoneNumber = "1234567891";
var pattern = /^[0-9]{10}$/;

exec() Method:
- is used to search for an occurrence(s) of a pattern in a given string.
- Returns an array with found pattern, it's index and some other extra properties otherwise returns null.

Note: exec method updates itself for the next match.

Syntax

Example code:
var myName = "I am Javascript. I am the best. I am lovely";
var pattern = /am/g;
var rArray=[];

{
}

Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.

=========================================

Follow the link for next video:
JavaScript Tutorial 89 - Regular Expression Flags in JavaScript

Follow the link for previous video:
JavaScript Tutorial 87 - String Methods in JavaScript | JavaScript String Methods

=========================================

JavaScript Tutorials Playlist:-

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-

jQuery UI Tutorials Playlist:-

Bootstrap Tutorials Playlist:-

=========================================

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
Рекомендации по теме
Комментарии
Автор

Welcome back to javascript Sir after long time.👍

ashokrathikrinda
Автор

Thank you for all the amazing tutorials.... I am truly grateful. Can you also do the tutorial on JavaScript on the console with node.js?

vikacademy
Автор

What are the different types of website names
How to upload website to Google after creating website
How to make Website name
We have buy domain and hosting for coding website

rainbowaquafreshrosystem
Автор

bro can you create a quick tutorial of css like html plzz can try it fast

ramuramu
Автор

Sir your s c programming tutorial are sufficient for competitive coding or not please tell

harshseth
Автор

plzz bro i am new to your channel i cant lesson all tutorials so i am asking better to lesson faster in 2 or 3 videos

ramuramu