Regular expression (RegEx) manipulation in JavaScript-quick mastery of regular expressions with handy examples ———— (translation has not been continued)

Source: Internet
Author: User

(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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.