- Import the module:
import re - Basic match:
re.search(r'cat', 'concatenate')→ finds'cat'anywhere. - Full match:
re.fullmatch(r'cat', 'cat')→ must match the entire string. - Find all:
re.findall(r'\d+', 'a1b22c333')→['1', '22', '333'] - Replace:
re.sub(r'\s+', ' ', 'too many spaces')→'too many spaces' - Character classes:
\ddigits,\wword chars,\swhitespace