Regular expressions
Regular expression, also known as regular expressions. (English: Regular Expression, often abbreviated as regex, regexp or RE in code), a concept of computer science. Regular expressions are usually used to retrieve and replace text that conforms to a certain pattern (rule).
Many programming languages support string manipulation with regular expressions. For example, a powerful regular expression engine is built in Perl. The concept of regular expression was originally popularized by tool software in Unix (such as sed and grep). Regular expressions are usually abbreviated as "regex". The singular numbers include regexp and regex, and the plural numbers include regexps, regexes, and regexen.
The following is a rule of using regular expressions, the specific content is as follows:
\d | Match any number in 0-9, equivalent to [0-9]
\D | Match non-numeric characters, equivalent to [^0-9]
\w | Match any letter, number or underscore, equivalent to [^A-Za-z0-9_]
\W | Matching with any non-letter, number or underscore character, equivalent to [^A-Za-z0-9_]
\s | Match any whitespace characters, including spaces, tabs, page breaks, equivalent to ?[\f\n\r\t\v]
\S | Match any non-whitespace character, equivalent to [^\f\n\r\t\v]
\n | Match newlines
\r | Match a carriage return
\t | Match tab characters
\v | Match vertical tab characters
\f | Match page break
These characters represent special meanings in regular expressions, such as: *, +,? ,\,
\ | Escape character, marking the next character as a special character
^ | Match the beginning of the string
$ | Match the position at the end of the string
* | Match the previous character or subexpression zero or multiple times
+ | Match the previous character or subexpression one or more times
? | Match the previous character or subexpression zero or once
. | "Point" matches any single character except "\r\n"
| | Or
[ ] | Character collection
( ) | Grouping, to match parentheses characters, please use "(" ? or ")"
Qualified characters, also known as quantifiers, are used to represent the number of matching characters.
* | Match the previous character or subexpression zero or multiple times
+ | Match the previous character or subexpression one or more times
? | Match the previous character or subexpression zero or once
{n} | n is a non-negative integer that matches the determined n times
{n,} | n is a non-negative integer, matched at least n times
{n,m} | n and m are non-negative integers, where n<=m; match at least n times, up to m times
Positioning characters are also called character boundaries. The marking matches not characters but positions that meet certain conditions, so the positioning characters are "zero-width".
^ | Match the beginning of the string, indicating the beginning
$ | Match the position at the end of the string, indicating the end
\b | Match a word boundary
Summarize
The above is the rules for using regular expressions introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!