filmov
tv
JavaScript RegExp Object & RegExp Methods | JavaScript Regular Expressions - JavaScript Tutorial 88
Показать описание
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
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
Комментарии