Python is free and open-source, and can be transplanted to multiple operating systems. As long as you do not need to use features dependent on specific operating systems, Python programs can run on various platforms without modification, next, we will study Python development tools.
To precisely find the word to, we should use \ bto \ B. Here, \ B is a special code specified by a regular expression, or a metacharacter. It represents the start or end of a word, that is, the division of a word. Although English words are generally separated by spaces, punctuation marks, or line breaks, \ B does not match any of these word delimiters. It only matches one position.
Again, it is reiterated that metacharacters \ B do not match the character but the position: the front and back of metacharacters are not all (one is, one is not or does not exist) \ w. Here \ w is also a metacharacter, which will be discussed later. Through the above example, I believe that the reader has a perceptual knowledge of regular expressions. Next we will introduce the metacharacters in detail.
Most letters and characters generally match themselves, or match their literal values. For example, the regular expression to exactly matches the string ". In addition, there are a few special characters that do not match themselves, but match something other than its literal value, which may be a character set, number of repetitions, or location. Common metacharacters include:
- class Category(models.Model):
- id = models.AutoField('id', primary_key=True)
- name = models.CharField(maxlength=50)
- code = models.CharField(maxlength=50)
- parentCategory = models.ForeignKey('self', 'id', null=True)
- enable = models.BooleanField()
-
- def __str__(self):
- return self.name
-
- class Admin:
- list_display = ('id', 'name', 'code', 'parentCategory')
This article will introduce these special characters one after another. However, let's take a look at the metacharacters used to match characters. First, the sentence ". "This metacharacter is usually used to match" any character ": Generally, it matches any character except the line break, but in alternate mode (re. DOTALL), which matches any character in the true sense, including line breaks.
The following metacharacters are [and]. They are often paired to specify a character set to match, that is, any element in the set can meet our requirements. The characters in the set can be listed individually. If these characters are consecutive, you can use the "-" separator to specify a character range.
For example, [abc] matches any character in "a", "B", or "c". Of course, the interval [a-c] can also be used to represent the same character set, the two indicate that the method is equivalent. To match all the vowels in a string, use the following code:
- class Category(models.Model):
- id = models.AutoField('id', primary_key=True)
- name = models.CharField(maxlength=50)
- code = models.CharField(maxlength=50)
- parentCategory = models.ForeignKey('self', 'id', null=True)
- enable = models.BooleanField()
-
- def __str__(self):
- return self.name
-
- class Admin:
- list_display = ('id', 'name', 'code', 'parentCategory')
Note that metacharacters are "downgraded" to common characters in square brackets. For example, [a.] match the character "a" or ". ". "is usually used as a metacharacter, but in the 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.
The Python development tool needs 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 effect: the metacharacter "^" is used as the first character of the set. For example, [^ 5] will match any character except "6.
- Python source code compilation skills
- Simple and Easy-to-use Python tools
- Introduction to the Python application field
- Python Android Object-Oriented Programming-Python applications
- How to Use the Python module to parse the configuration file?