Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the commonly used regular expressions

Shulou Source: shulou.com Published: 2022-06-02 11:17:02 10月02日 Update

This article is about the regular expressions commonly used to share with you, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it.

What is a regular expression?

A regular expression is a search pattern formed by a sequence of characters.

When you search for data in text, you can use search patterns to describe what you want to query.

A regular expression can be a simple character or a more complex pattern.

Regular expressions can be used for all text search and text replacement operations.

This article introduces some common regular expressions (money, non-negative integers, positive integers, mailboxes, mobile phone numbers). The details are as follows:

Character

[amurz] stands for the letter amurz

[^ amurz] the representative is not in aMuz.

[0-9] stands for 0-9

[^ 0-9] means not in 0-9.

\ d is equivalent to [0-9]

\ d is equivalent to [^ 0-9]

Qualifying character

* represents the previous subexpression 0 or more times

+ represents one or more times

? For 0 or 1 time

{n} represents n times

{n,} represents n to infinite times

{nmenthm} represents n to m times.

Common expression

Money: / (^ [1-9] ([0-9] +)? (\. [0-9] {1jue 2})? $) | (^ (0) {1} $) | (^ [0-9]\. [0-9] ([0-9])? $) /

Money is reserved for two decimal places, and the first letter cannot be 0. Unless it's a little past zero or zero. The above is divided into three parts. A decimal at the beginning of 1-9, a decimal at the beginning of 0-9

Email: / ^ [a-zA-Z0-9 zA-Z0. -] + @ [a-zA-Z0-9 -] + (\. [a-zA-Z0-9 -] +) *. [a-zA-Z0-9] {2jue 6} $/

Matching format XXX@qq.com XXX@XX.com.cn

Positive integer: / ^ [1-9] [0-9] * $/

Integer: / ^ [0-9] * $/

Mobile phone number: / ^ 1 [0-9] {10} $/ matching format is 11 digits starting with 1. Because it doesn't have to be an exact match all the time, it's all 11 digits at the beginning of 1.

The above are the commonly used regular expressions, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Representatives expressions regular commonly used characters beginnings integers search text patterns money content numbers letters decimals mobile phones mobile numbers more formatting knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Redmi Linux macOS Shulou Tech Info