天天看點

PYTHON 正則表達示入門

确實是實踐出真知,自己手打代碼之後,以前停在理論上的東東,慢慢可以進入實戰了。

比如,match和search之間的差別。

PYTHON 正則表達示入門
PYTHON 正則表達示入門

>>> ================================ restart ================================

>>>

hello

world

['one', 'two', 'three', 'four', '']

['1', '2', '3', '4']

1 2 3 4

m.string: hello world!!

m.re: <_sre.sre_pattern object at 0x00000000029f9a70>

m.pos: 0

m.endpos: 13

m.lastindex: 3

m.lastgroup: sign

m.group(1,2): ('hello', 'world')

m.groups(): ('hello', 'world', '!!')

m.groupdict(): {'sign': '!!'}

m.start(2): 6

m.end(2): 11

m.span(2): (6, 11)

m.expand(r'\2 \1 \3'): world hello!!

p.pattern: (\w+) (\w+)(?p<sign>.*)

p.flags: 16

p.groups: 3

p.groupindex: {'sign': 3}

say i, world hello!

('say i, world hello!', 2)

i say, hello world!

('i say, hello world!', 2)