Both Python2 and Python3 have two types of strings
Str
bytes
Re module
The Find-class functions are exact lookups.
String is a fuzzy match
FindAll (Pattern,string,flags)
Replace function
' Hello python '. replace (' P ', ' P ')
' Hello Python '
A= ' sadfadf232wwewfr323rwef34534trwef '
Import re
W=re.findall (' \d ', ' sadfadf232wwewfr323rwef34534trwef ')
W=re.findall (' \d+ ', ' sadfadf232wwewfr323rwef34534trwef ')
Print (W)
Re.findall the results of all conforming rules to a list.
Re.findall (pattern,string)
Key: Meta-character (character with special function)
Wildcard characters:
. A point can match any symbol except a newline character, which means that the point can represent any symbol.
* [0,+00] 0 to infinity Range
+ [1,+00] 1 to infinity Range
? [0,1] 0 or 1 x
{} {N,m} can write {3,5} 3 to 5 can also write {3} 3, you can also write {0,} infinite times meaning
Character:
[] Usage, re.findall ("A[bd]c", "SAFASDFAEFSDF") inside [BD] is or is the relationship, or B or D are displayed
If the punctuation is added to the [], the punctuation and the letter are the same as the content of a, B, and so on.
[] If you add a wildcard, then there is no wildcard meaning, just match the content of the relevant symbol.
[0-9] Just match a number, if you need to find 4 digits, [0-9]{4}
[] characters with special meanings in the character set are:-^ \
^ Start Matching
$ End Match
(): Group
(AD) matches this group
(AD) in the +yuan graph below this match is blue content, but grouping first displays () the contents within the group, so the result is the ad
As shown, you can cancel () the priority, print the blue content,?: This syntax is to cancel the priority, not only to display the grouping, but also to display other content.
For example, the printed content is 3, because there are many numbers, matching to yuan, but displaying grouped content 3
Ungroup Attributes
The meaning of a.
Empty if or after no match is shown.
For example, the above can directly match the URL.
Translate, translate letters into special meanings, and transfer characters of special meaning to ordinary characters
\d represents any one character of 0-9
\w a character that represents any number or letter
\. Point becomes normal symbol
A bit more complicated.
\s out, there's a space.
Search method
Find a corresponding one that no longer matches backwards
Match method
Matches only the beginning, or none if not at the beginning
Homework
Group names to groups, pick content by name
Special symbols that can be used in a character set
| pipe character
Python Learning section 14th (Regular)