Home > Web Front-end > JS Tutorial > body text

Understanding regular expressions in JS

小云云
Release: 2018-02-27 14:19:33
Original
1991 people have browsed it

1. What are regular expressions? Regular expressions: rules, which allow computers to understand the rules we write. In essence, regular expressions are a set of regular strings. a

2 How to learn Regular expression

\d represents numbers
\D represents non-digits
\s represents spaces

1) 用这些特定的字符去写一套规则(我想要的规则,我想要一套邮箱的规则、qq号的规则、电话号码的规则等等)
2) 使用的时候,拿需要判断的内容放到这套规则里面去检测
Copy after login
Copy after login

3 Some methods related to regular expressions in js
Test
Repalce
match
Search
4 Matching sub-item (sub-pattern) – ()
5 Character class – []
1 contains the relationship of or
2 Can write range [0-9][a-z][A-Z]
3. Use ^ inside [] to indicate non. Note: Use ^ outside [] to indicate the beginning
6 Escape characters
. represents any character in the regular expression, and . is converted into a real character.
\b \B
\s \S
\d \D
\w \W
\1 Repeat the first sub-item \2 \3 …
7 Quantifier Modifies the quantity
{4, 7} Greater than or equal to 4 Less than or equal to 7
{4, } greater than or equal to 4
{4} is equal to 4
? 0 times or 1 time
* Greater than or equal to 0
+ Greater than or equal to 1

1 What is a regular expression

Regular: Rules, so that the computer can understand the rules we write

Essentially speaking, a regular expression is a String of group rules, a

2 How to learn regular expressions

\d represents numbers
\D represents non-digits
\s represents spaces

1) 用这些特定的字符去写一套规则(我想要的规则,我想要一套邮箱的规则、qq号的规则、电话号码的规则等等)
2) 使用的时候,拿需要判断的内容放到这套规则里面去检测
Copy after login
Copy after login

3 Some methods related to regular expressions in js
Test
Repalce
match
Search
4 Matching sub-item (sub-pattern) – ()
5 Character class – []
1 contains the relationship of or
2 Can write range [0-9][a-z][A-Z]
3. Use ^ inside [] to indicate non. Note: Use ^ outside [] to indicate the beginning
6 Escape characters
. represents any character in the regular expression, and . is converted into a real character.
\b \B
\s \S
\d \D
\w \W
\1 Repeat the first sub-item \2 \3 …
7 Quantifier Modifies the quantity
{4, 7} Greater than or equal to 4 Less than or equal to 7
{4, } greater than or equal to 4
{4} is equal to 4
? 0 times or 1 time
* Greater than or equal to 0
+ Greater than or equal to 1

Related recommendations:

The principles of regular expressions in js

Summary of the creation and creation of regular expressions in js Use

How to use regular expressions in js?

The above is the detailed content of Understanding regular expressions in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!