This time I will bring you detailed graphic and text explanations of using regular multi-line mode and single-line mode. What are the precautions when using regular multi-line mode and single-line mode. The following is a practical case. Let’s take a look. one time.
In Expresso, test "multiline mode"
Test one
Note: Here is a sample There is no carriage return after 3eeeeee in the text, and the cursor is right after e. The matching result is 3eeeee, as shown in the Search Results area above.
Why can't 1abcde and 2abc match here?
Turn on multi-line mode
^ It can match the beginning of string (the starting position of the string), or it can match the beginning of the line (i.e. The position after the newline character \n)
$ can match the end of the string (the end position of the string), or the end of the line (that is, the position before the newline character \n)
Turn off multi-line mode
^ Can only match the beginning of the string
$ Can only match the end of the string
Knowledge points: \r is a carriage return character, \n is a newline symbol. In Windows, what we usually call line feed is essentially carriage return first and then line feed; there is a more detailed explanation below.
As shown in the picture above: \r matches [CR], \n matches [LF] <—— CR is carriage return LF is line feed
Multiple strings A paragraph, for example,
ab
cd
e
in Windows operating system is actually: ab[CR][LF]cd[CR][LF]e
in Windows, The carriage return and line feed in the text are stored as: 0D 0A. In other words, what is stored first is "carriage return\r"
CR is represented by the symbol '\r', and the ASCII code is 13, ten Hexadecimal is 0x0D;
LF is represented by the symbol '\n', ASCII code is 10, hexadecimal is 0x0A;
Regular expression: (?m) ^(\d\w+)(\s*)$
Sample text
##Matching result In Expresso and PHP, when multi-line mode is enabled, "$" matches the end of the string or the position before "\n".Single-line mode
Enable single-line mode: .Can match any character (including newline characters)Turn off single-line mode: .Only match non-newline characters
Other Any characters (. can match \r, that is, all characters except \n are not matched.)
Single-line mode affects the matching of .
The single-line mode affects the matching range of the decimal point "."
The multi-line mode affects the matching range of "^" and "$" Matching scope
Global mode is a concept only found in some scripting languages
When matching, turn off the global mode, similar to the Match method in .NET, turn on the global mode, similar to .NET The Matches method
turns off the global mode when performing a replacement, similar to replaceFirst in Java, and turns on the global mode, similar to replaceAll
function in PHP; turn on the global mode, similar to the preg_ match_ all function in PHP)
I believe you have mastered the method after reading the case in this article. For more exciting things, please pay attention to php Other related articles on the Chinese website! Recommended reading:Detailed explanation of the use of PHP regular zero-width assertions
How to implement the fuzzy matching function of regular expressions
The above is the detailed content of Detailed graphic and text explanation of using regular multi-line mode and single-line mode. For more information, please follow other related articles on the PHP Chinese website!