Dup Ver Goto 📝

Python Regex 001

PT2/lang/python/regex python regex does not exist
To
29 lines, 70 words, 650 chars Page 'Regex_001' does not exist.

The official docs.

Flags

r.search(subject,re.I|
re.search(pattern,subject,re.I)

Match Objects

m = re.search(pattern,subject)
m.group(0) # whole match
m.group(1) # capture groups
m.start(), m.end() # location of match in subject

# so
left = subject[:m.start()]
mid = subject[m.start():m.end()]
right = subject[m.end():]

Findall

See the docs

re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest')
['foot', 'fell', 'fastest']
re.findall(r'(\w+)=(\d+)', 'set width=20 and height=10')
[('width', '20'), ('height', '10')]