Basic guide for JavaScript Regular Expressions 🚀
👇🧵
👇🧵
Don't forget to bookmarked it for future reference..
★ Regular Expressions
• Regular expressions, also known as RegExp, are a way to match patterns in strings.
• They are used in many programming languages to search, replace, and validate text.
• Regular expressions, also known as RegExp, are a way to match patterns in strings.
• They are used in many programming languages to search, replace, and validate text.
• These patterns are used with the exec and test methods of RegExp, and with the match, replace, search, and split methods of String.
• Syntax :/pattern/modifiers;
• Modifiers are used to perform case-insensitive and global searches.
• Syntax :/pattern/modifiers;
• Modifiers are used to perform case-insensitive and global searches.
★ Here is a basic example of how to use regular expressions in JavaScript:
const regex = /cat/;
const string = "The cat in the hat.";
const result = regex.test(string); //Returns true
const regex = /cat/;
const string = "The cat in the hat.";
const result = regex.test(string); //Returns true
We can also create a regular expression by calling the RegExp constructor function:
const regex = new RegExp("cat");
const string = "The cat in the hat.";
const result = regex.test(string);
// Returns true
const regex = new RegExp("cat");
const string = "The cat in the hat.";
const result = regex.test(string);
// Returns true
★ Regular expressions can include a variety of different characters and patterns to match specific types of characters or groups of characters.
For example, the following regular expression will match any string that contains a digit:
const regex = /\d/;
const string = "The cost is $19.95.";
const result = regex.test(string);
// Returns true
• Here '/d' is Metacharacter with a special meaning to Find a digit.
const regex = /\d/;
const string = "The cost is $19.95.";
const result = regex.test(string);
// Returns true
• Here '/d' is Metacharacter with a special meaning to Find a digit.
There are many other things that you can do with regular expressions in JavaScript, such as search and replace, or split a string into an array of substrings.
End thread 🧵
End thread 🧵
If this thread helpful for you then :
1. Do Retweet the FIRST TWEET.
2. Follow me and turn on the notifications: @personalvipin
HTML
CSS
Javascript
Thank you ❤️
1. Do Retweet the FIRST TWEET.
2. Follow me and turn on the notifications: @personalvipin
HTML
CSS
Javascript
Thank you ❤️
جاري تحميل الاقتراحات...