Un exemple simple pour tester si une chaîne de caractères commence par une tabulation sous python en passant par la méthode startswith():
>>> s = ' abcdefg'
>>> s
'\tabcdefg'
>>> s.startswith('\t')
True
Autre exemple avec un texte sur plusieurs lignes:
>>> txt = '''hello
... how
... are
... you
... today ?
... '''
>>> print(txt)
hello
how
are
you
today ?
>>> line_list = txt.splitlines()
>>> for idx,line in enumerate(line_list):
... if line.startswith('\t'):
... print(idx,line)
...
3 you
Références
Liens | Site |
---|---|
Check if string starts with tab | stackoverflow |
Regular Expressions by Example | flockhart.virtualave.net |
Python String startswith() Method | tutorialspoint |
How to check whether a line starts with a word or tab or white space in python? | stackoverflow |
Checking whether a string starts with XXXX | stackoverflow |