In my text, I want to replace all leading tabs with two spaces, but leave the tabs without a leading.
For instance:
a
\tb
\t\tc
\td\te
f\t\tg
( "a\n\tb\n\t\tc\n\td\te\nf\t\tg")
should turn into:
a
b
c
d\te
f\t\tg
( "a\n b\n c\n d\te\nf\t\tg")
In my case, I could do this with a few replace operations, repeating as many times as the maximum level of nesting or until nothing changes.
But is it also impossible to do in one pass?
I tried, but could not come up with something, the best I came up with was a search:
re.sub(r'(^|(?<=\t))\t', ' ', a, flags=re.MULTILINE)
Which "only" makes the wrong replacement (second tab between fand g).
, , (, , ), "count" regex, , ( [cs.se]).
Python, .