(Original: HTTPS://BLOG.BITSRC.IO/A-BEGINNERS-GUIDE-TO-REGULAR-EXPRESSIONS-REGEX-IN-JAVASCRIPT-9C58FEB27EB4)
When you first see the regular, they are like random stacked characters that look meaningless. But although they seem tricky (because of the complex grammatical rules), they are extremely useful.
The truth is, a proper understanding of regular expressions can make you a smarter programmer. To fully understand the world of regular expressions, you need to learn some basic concepts before you can make a difference.
Don't say much nonsense, let's get started.
What are regular expressions (Regular expression)
A regex is a way to describe a string pattern. The expressions used to describe or match form a unique, small programming language that ranks among the languages-JavaScript, Perl, Python, PHP, and Java.
The regex allows you to examine strings such as e-mail addresses or passwords, and to find elements that match the previously developed feature pattern, extracting these valid elements and processing them.
Create a regular expression
In JavaScript, there are two ways to create a regex. It can be used either through the ' RegExp ' constructor or with a forward slash (/) to encapsulate the matching model.
Regular expression constructors:
Grammar:
New REGEXP (pattern[, flags]);
Example:
var New REGEXP (' abc ');
the original ecological regular expression :
Grammar:
/pattern/flags;
Example:
var regexliteral =/abc/;
? The flags here are optional and I will explain them later in this article.
In some cases, we need to create a dynamic regular expression, when the original ecology is no use, we must use the constructor.
Either way, a schema object is created, and the pattern object in both ways has the same functionality and characteristics.
Because you are using a forward slash (/) to create a matching pattern, you should avoid misusing the backslash (\).
Regular-expression testing
Simple Match mode
Some special characters
Practical Practice
Summarize
---restore content ends---
(translated) Regular Expressions (RegEx) exercises in JavaScript-quick mastery of regular expressions with handy examples ———— (translation is not over)