Tab Character in PY
Match literal tab characters — the regex behind every formatter / linter that yells about indentation.
Try it in the PY tester →Pattern
regexPY
\t (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"\t")
input_text = " spaces\there"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
\t is the escape for the tab character (U+0009). The g flag finds every occurrence. Pair with `replace(re, ' ')` for tabs-to-spaces conversion or use it as a detector to flag mixed indentation.
Examples
Input
spaces\thereMatches
\t
Input
\t\tdouble tabMatches
\t\t
Input
no tabs at allNo match
—