Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of regular expression of Nginx

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx (engine x) is a high-performance HTTP and reverse proxy service, as well as an IMAP/POP3/SMTP service. Nginx was developed by Igor Sesoyev for the second most visited Rambler.ru site in Russia. The first public version 0.1.0 was released on October 4, 2004.

It distributes the source code as a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low consumption of system resources. Nginx 1.0.4 was released on June 1, 2011.

Nginx is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server, and is distributed under a BSD-like protocol. It is characterized by low memory and strong concurrency ability. in fact, the concurrency ability of nginx does perform well in the same type of web server. Chinese mainland uses nginx website users: Baidu, JD.com, Sina, NetEase, Tencent, Taobao and so on.

Today, let's talk about the rules for the use of his regular expressions. I'll give a few examples and explain them.

What is a 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.

Regular expressions consist of some ordinary characters and some metacharacters (metacharacters). Ordinary characters include uppercase and lowercase letters and numbers, while metacharacters have special meanings, which we will explain below.

In the simplest case, a regular expression looks like a normal lookup string. For example, the regular expression "testing" does not contain any metacharacters, which can match strings such as "testing" and "testing123", but not "Testing".

If you want to really use regular expressions, the correct understanding of metacharacters is the most important thing. The following table lists all the metacharacters and a short description of them.

Metacharacter

Description

\

The next character token, or a backward reference, or an octal escape character. For example, "\ n" matches\ n. "\ n" matches a newline character. The sequence "\" matches "\" and "(" matches "(". That is, it is equivalent to the concept of "escape characters" in many programming languages.

^

Matches the beginning of the input word. If the Multiline property of the RegExp object is set, ^ also matches the position after "\ n" or "\ r".

$

Matches the end of the input line. If the Multiline property of the RegExp object is set, $also matches the position before "\ n" or "\ r".

*

Matches the previous subexpression any number of times. For example, zo* can match "z" as well as "zo" and "zoo". * is equivalent to {0,}.

+

Matches the previous subexpression one or more times (greater than or equal to 1). For example, "zo+" matches "zo" and "zoo", but not "z". + is equivalent to {1,}.

?

Matches the previous subexpression zero or once. For example, "do (es)?" Can match "do" or "does". ? It is equivalent to {0jue 1}.

{n}

N is a non-negative integer. Match the determined n times. For example, "o {2}" does not match "o" in "Bob", but can match two o in "food".

{n,}

N is a non-negative integer. Match at least n times. For example, "o {2,}" does not match "o" in "Bob", but does match all o in "foooood". "o {1,}" is equivalent to "o +". "o {0,}" is equivalent to "o *".

{n,m}

M and n are non-negative integers, where n

Non-acquisition matching, reverse negative pre-checking, similar to positive negative pre-checking, but in the opposite direction. For example, "(?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report