python core programming exercises 1-2 regular expression matches any words separated by a single space title right, and that is the name

# Matches any words separated by a single about whitespace , that is, first and last name
. 1  Import Re
 2  
. 3 PATT = ' [A-Za-Z] + [A-Za-Z] + '   # A method + + operator match its left regular expression occurs at least once a case 
. 4  # PATT = ' [A-Za-z] + [A-Za-z] + '# method II 
. 5 # PATT = ' [A-Za-Z] + \ S [A-Za-Z] + ' # method three
. 6 NAME1 = ' Zhang San ' . 7 NAME2 = ' Li Si ' . 8 NAME3 = ' Wang ermazi ' . 9 10 m = re.match (PATT, NAME1) . 11 M1 = re.match (PATT, NAME2) 12 is M2 = re.match(patt, name3) 13 if m is not None: 14 print(m.group()) 15 if m is not None: 16 print(m1.group()) 17 if m is not None: 18 print(m2.group())

"" "
/Usr/bin/python3.5 / studydisk / OTHER / regular expression /demo2.py
zhang San
li Si
wang ermazi
" ""

Guess you like

Origin www.cnblogs.com/ranxf/p/11365243.html