3.2 re -- Regular expression operations, re -- regular
This module provides regular expression matching operations. Its functions are the same as those in Perl.
Whether it is a Unicode string or a single-byte 8-Bit String, you can use the pattern matching and string search functions. However, it should be noted that Unicode strings and 8-bit strings cannot be used in combination, that is, you cannot match the single-byte mode in Unicode, or other search functions. Similarly, strings cannot be replaced with each other in different types of strings.
Regular Expressions use backslash ('\') to specify the meaning of a specific format, or allow specific characters. To solve the problem of using the backslash ('\'), the solution is the same as that used in string formatting. For example, to match a double backslash ('\'), you need to use the '\' format, because each two double backlash ('\') represents a diagonal line.
However, you can also use another method to represent the string of a regular expression. You do not need to use this troublesome method, that is, use the start of the 'R' character to represent the processing of the original string. For example, writing R' \ n' is a string that represents two characters: \ and n. If the string '\ n' does not start with r, It is a character string, it indicates a newline character.
One thing to note is that all functions and methods related to regular expressions are in the section of the object for compiling regular expressions, but it does not mean that these functions and methods can be used only by compiling regular expressions, but it can be used directly, but there will be some performance loss, or you need to enter more parameters.
Cai junsheng QQ: 9073204 Shenzhen
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.