In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the delimiter and atom introduction in PHP regular expression". The explanation in this article is simple and clear and easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "delimiter and atom introduction in PHP regular expression".
Let's first take a look at the delimiters of regular expressions, the composition of regular expressions, and the preg_match () function:
1, the delimiter of the regular expression.
Any character except letters, numbers and backslashes can be delimited symbols, such as |, / /, {},! Etc., but it is important to note that if there is no special need, we all use the forward slash / / as the delimiting symbol of the regular expression.
2, the composition of regular expressions.
Let's take a look at this formula: / atom and metacharacter / pattern modifier
That is, the regular expression's atoms and metacharacters are placed between delimiters, while pattern modifiers are placed outside delimiters.
3The pregandmatch () function
We will explain in more detail later, but this is just to help with the test, which returns a Boolean value indicating whether the match is successful or not.
After understanding the above simple content, let's get to the point.
Atoms in regular expressions
What is an atom? An atom is the most basic unit of a regular expression and must contain at least one atom. As long as a regular expression can be used alone, it is an atom.
This concept may seem vague, but it doesn't matter. Let's take a look at the composition of atoms in regular expressions.
Atomic composition mode
1, all printed (all strings that can be output on the screen) and non-printed characters (invisible, such as spaces, newline characters, etc.)
2. If all meaningful characters want to be used as atoms, you can escape them with the "\" escape character. Such as:\. \ *?\ (\.
Note: "\" escape characters can convert meaningful characters into meaningless characters, and you can also convert meaningless characters into meaningful characters. For example:\ d represents any decimal number.
3, you can directly use some of the range atoms provided by the system in regular expressions, as shown in the following table:
The atomic specification representing the range the custom atomic representation\ d represents any decimal number [0-9]\ D represents any character other than the number [^ 0-9]\ s represents any white space character Space,\ n\ r\ t\ f [\ n\ r\ t\ f]\ S represents any non-blank [^\ n\ r\ t\ f]\ w represents any word a-zA-Z0-9 _ [a-zA-Z0-9 _]\ W represents any non-word, any character other than a-zA-Z0-9 _ [^ a-zA-Z0-9 _]
4, customize the atomic table (using square brackets []), you can match any 1 atom in the formula brackets.
In the above table, we have converted the range atoms provided by the system in a custom way. Since the system cannot provide all the atoms I need, it is necessary to customize the atomic list. For example, if we want to match letters or numbers, we need to write atoms as [a-zA-Z0-9].
It is important to note here:
A, the symbol "-" indicates a range, such as [a murz] for lowercase letters a to z, but never write it in the form of [a murz 9]!
B, the symbol "^" means inversion, which must be placed at the beginning of square brackets. For example, if we want to match non-numbers, the atom is [^ 0-9].
Let's take a look at an example of the use of regular expression atoms, with the following code:
The copy code is as follows:
Note: one of the atoms in the custom atomic table is matched by a string, and the match is successful. Removing the square brackets from the custom atomic table matches the entire string. For example,'/ abc/' 'means that there must be an abc substring in the string to be matched, while' / [abc] / 'means that any character in the string that contains a, b, and c is matched.
You can modify the pattern in the above example (that is, the pattern variable $pattern of the regular expression) to verify the atom of the regular expression we are talking about in this section.
Thank you for reading, the above is the content of "delimiter and atomic introduction in PHP regular expression". After the study of this article, I believe you have a deeper understanding of the problem of delimiter and atomic introduction in PHP regular expression, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.