Python regular expression processing commonly used functions

Python commonly used regular expression handler

Regular expressions are a special character sequence, the expression of a set of strings for simple features, and checks whether a character string matching a pattern, very convenient to use.

In Python, by calling us re to use a library re module:

import re

 

Here Python regular expressions common handler.

 

re.match function

re.match function from the start position of the string matching the regular expression match returns the object, starting position if not successful match, match () returns N One .

re.match(pattern, string, flags=0)

pattern: match the regular expression.

string: string to be matched.

the flags: flags, for controlling the regular expression matching method, such as: whether or not case-sensitive, multi-line matching and the like. See also: Regular expression modifier - optional flag

 

Use group (num) or groups () matches the object function to obtain the match expression:

group (num = 0): match the entire string expression, Group () may be a plurality of input group number, then it returns those containing a group corresponding to the tuple values.

groups (): returns a string containing the tuple all groups, Group 1 to the number contained.

Guess you like

Origin www.cnblogs.com/BIXIABUMO/p/12041544.html