Complete regular expression manual for php tutorial
Foreword
Regular expressions are cumbersome, but powerful. After learning, applying them will not only improve your efficiency, but also give you an absolute sense of accomplishment. As long as you read these materials carefully and make certain references when applying them, mastering regular expressions is not a problem.
Index
1._Introduction
2._History of regular expressions
3._Regular expression definition
3.1_Normal characters
3.2_Non-printing characters
3.3_Special characters
3.4_Qualifier
3.5_locator
3.6_Select
3.7_Back reference
4._Operation priority of various operators
5._Explanation of all symbols
6._Some examples
7._Regular expression matching rules
7.1_Basic pattern matching
7.2_Character cluster
7.3_Determine recurrence
1. Introduction
At present, regular expressions have been widely used in many software, including *nix (linux, unix, etc.), operating systems such as HP, development environments such as php, c#, java, etc., as well as many application software. Regular expression shadow.
The use of regular expressions can achieve powerful functions in a simple way. In order to be simple and effective yet powerful, the regular expression code is more difficult and not easy to learn, so it requires some effort. After getting started, it is relatively simple and effective to use it by referring to certain references.
Example: ^.+@.+..+$
Code like this has scared me away many times. Maybe many people are scared away by such code. Continuing reading this article will give you the freedom to apply code like this too.
Note: Part 7 here seems to be somewhat repetitive with the previous content. The purpose is to re-describe the parts in the previous table to make these contents easier to understand.
2. History of regular expressions
The “ancestors” of regular expressions can be traced all the way back to early research on how the human nervous system works. Two neurophysiologists, warren McCulloch and walter pitts, developed a mathematical way to describe these neural networks.
In 1956, a mathematician named Stephen Kleene published a paper titled "Representation of Neural Network Events" based on the early work of McCulloch and Pitts, introducing the concept of regular expressions. Regular expressions are used to describe expressions that he calls "the algebra of regular sets," hence the term "regular expression."
Subsequently, it was found that this work could be applied to some early research on computational search algorithms using the tutorial of ken thompson, the main inventor of unix. The first practical application of regular expressions was the qed editor in unix.
As they say, the rest is history as we all know. Regular expressions have been an important part of text-based editors and search tools ever since.
3. Regular expression definition
Regular expression (regular expression) describes a string matching pattern, which can be used to check whether a string contains a certain substring, replace the matching substring, or extract from a string that meets a certain condition substrings, etc.
When listing directories, *.txt in dir *.txt or ls *.txt is not a regular expression, because the meaning of * here is different from the * in regular expressions.
Regular expressions are text patterns composed of ordinary characters (such as the characters a through z) and special characters (called metacharacters). A regular expression acts as a template that matches a character pattern with a searched string. 1 2 3 4 5