Clear and transparent Python language description

Source: Internet
Author: User

The Python language is a clear language. Another meaning is that its authors intentionally design highly restrictive syntaxes to make bad programming habits, such as not indent to the right of the next line of the if statement) cannot be compiled.

As mentioned above, "." is usually used as a metacharacter, but in character set combination, its particularity will be deprived and restored to normal characters. In this case, you can modify the above Code to perform an experiment. Sometimes you need to find characters that do not belong to a character set. For example, if you want to search for any character except the number 6, you need to use the negative sense.

The metacharacter "^" is used as the first character of the set. For example, [^ 5] matches any character except "6. The Backslash "\" is a very important metacharacter. We know that in Python strings, The backslash is also used as a special character (or escape character). It can be followed by different characters to indicate different special meanings;

It can also be used to cancel all metacharacters so that you can match them in the mode. For example, if you need to match the character "\", you can use a backslash to cancel their special meaning :\\. Below are some metacharacters that combine "\" with other characters. They generally represent some predefined character sets, as shown below:

We have already discussed how to specify the number of repetitions for a single character-simply add a qualifier after the character. Now let's take a look at the eight methods for repeating multiple characters: you can use parentheses to indicate the subexpression (also called grouping ).

Then you can specify the number of times the subexpression repeats. You can also perform other operations on the subexpression. We know that IP addresses are the four numbers separated by periods, and each number cannot exceed 255. (\ D {1, 3} \.) {3} \ d {1, 3} is a simple IP address matching expression.

Where: \ d {1, 3} matches 1 to 3 digits (\ d {1, 3 }\.) {3} matches three digits with an English ending (this group is used as a whole), repeats three times, and finally adds one to three digits (\ d {1, 3 }). However, it will also match an impossible IP address such as 256.300.888.999. If arithmetic comparison can be used, this problem may be solved simply, but regular expressions do not provide any mathematical functions.

Therefore, you can only use lengthy grouping, selection, and Character Set combination to describe a correct IP Address: (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?). The key to understanding this expression is to understand 2 [0-4] \ d | 25 [0-5] | [01]? \ D ?, After the above introduction, I believe that the readers can analyze its meaning.

  1. Python source code compilation skills
  2. Simple and Easy-to-use Python tools
  3. Introduction to the Python application field
  4. Python Android Object-Oriented Programming-Python applications
  5. How to Use the Python module to parse the configuration file?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.