22.Python regular expressions

A. Regular Expressions

A rule saying I already know you're dizzy, now let's look at some practical applications. Online testing tool  http://tool.chinaz.com/regex/

First you have to know is talking about regular, and it is only related to the string. I'll give you the tools provided, every word you type is a string. 
Second, if a value in one location, what changes will not occur, then the rule is not required.
  For example, you use the "1" to match "1" or a "2" to match "2", can be directly matched. They even python string manipulation can easily do it.
After more then we need to consider is the range in the same position may appear characters.
Character Group: [set of characters]
In various characters may appear in the same position to form a character group, said in a regular expression with []
Character divided into many categories, such as numbers, letters, punctuation, and so on.
If you now ask for a location "only appears a number", then the characters on this position is only one of the 10 number 0,1,2 ... 9.

 

 

 

 character:

 

 

 

 quantifier:

 

 

 

 

 

 Note: The previous *, + ,? are all greedy matching, matching is possible, followed by a plus sign so that it becomes inert match?

 

 

 

 

 

 

 

 

 

 

 

 

Is any character
* is set to 0 to infinite length
? Non-greedy mode.
He is with any of the characters take as little as possible, so generally do not write alone, he mostly used in:
. * The X-?

Character is taken in front of any length, x appears until a

Guess you like

Origin www.cnblogs.com/xuweng/p/12199288.html