I am trying to process a multi-lines string, replace and remove some lines. here is the code.
>>> txt
'1 Introduction\nPart I: Applied Math and Machine Learning Basics\n2 Linear Algebra'
>>> tmp = []
>>> for line in txt.splitlines():
... if re.findall('[0-9]', line):
... replaced = re.sub('[0-9]', '#', line)
... tmp.append(replaced)
>>> print(tmp)
['# Introduction', '# Linear Algebra']
this piece of code has done my job though, I am not sure if it is the most efficient way.
i tried this post and doc, it seems that none of their multiple find is for multi-lines.
is there a more efficient way to do this?