Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the rules for the use of regular expressions

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

This article introduces you what are the rules for the use of regular expressions, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Regular expression

Regular expression, also known as regular expression. (English: Regular Expression, often abbreviated as regex, regexp or RE in code), a concept in computer science. Regular expressions are often used to retrieve and replace text that conforms to a certain pattern (rule).

Many programming languages support string manipulation using regular expressions. For example, a powerful regular expression engine is built into Perl. The concept of regular expressions was first popularized by tools in Unix, such as sed and grep. Regular expressions are usually abbreviated to "regex". The singular has regexp and regex, and the plural has regexps, regexes, and regexen.

Here are the rules for using regular expressions. The details are as follows:

\ d | match any number in 0-9, which is equivalent to [0-9]

\ d | match non-numeric characters, equivalent to [^ 0-9]

\ w | match any letter, number or underscore, which is equivalent to [^ A-Za-z0-9 _]

\ W | matches any non-alphanumeric or underscore character, which is equivalent to [^ A-Za-z0-9 _]

\ s | matches any white space characters, including spaces, tabs, page breaks, which is equivalent to? [\ f\ n\ r\ t\ v]

\ s | matches any non-white space character, which is equivalent to [^\ f\ n\ r\ t\ v]

\ n | match newline character

\ r | match a carriage return character

\ t | match the configuration table character

\ v | match vertical tabs

\ f | match the feed character

These characters have special meanings in regular expressions, such as *, +,? ,\

\ | escape character and mark the next character as a special character

| ^ | matches the position where the string begins |

| $| matches the position at the end of the string |

| * | match the previous character or subexpression zero or more times |

| + | matches the previous character or subexpression one or more times |

? | match the previous character or subexpression zero or once

. | | "Dot" matches any single character except "\ r\ n" |

| | or |

[] | character collection

() | grouping. To match parenthesis characters, use "("? Or ")"

Qualifying characters, also known as quantifiers, are used to indicate the number of characters that match.

| * | match the previous character or subexpression zero or more times |

| + | matches 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, matching determined n times

{n,} | n is a non-negative integer, matching at least n times

{n ~ (m)} | n and m are non-negative integers, where n

Tags: Characters expressions rules positions strings numbers content tabs integers tabs special underscores letters right and wrong more tags concepts whitespace boundaries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Shulou Tech Info macOS Microsoft