Python学习随记(十三):正则表达式(2)
import re
a = 'a,b,c,d,e'
print(a.split(","))
a = "a,b|c#d,,e"
print(a.replace("|", ",").replace("#", ",").split(","))
print(re.split(r"[,|#]+", a))
print(re.split("[,;\s]+", "a,b;; c d"))
id_str = '340122200601014212'
print(re.match("(\d{6})(\d{8})(.*)", id_str).groups())
print(re.match("(\d{6})(\d{8})(.*)", id_str).group(0))
print(re.match("(\d{6})(\d{8})(.*)", id_str).group(1))
print(re.match("(\d{6})(\d{8})(.*)", id_str).group(2))
time_str = '09:09:10'
print(re.match("([0-1][0-9]|2[0-3]):([0-5]\d):([0-5]\d)", time_str).group(1))
print(re.match("([0-1][0-9]|2[0-3]):([0-5]\d):([0-5]\d)", time_str).group(2))
print(re.match("([0-1][0-9]|2[0-3]):([0-5]\d):([0-5]\d)", time_str).group(3))
print(re.match("(\d+?)(0*)$", '10230000').groups())
num0_pattern = re.compile("(\d+?)(0*)$")
print(num0_pattern.match("10230000").groups())
print(num0_pattern.match("10230"))
print(num0_pattern.match("102"))
print(num0_pattern.match("102300000000"))