I'm looking to leverage regex syntax to create an indent (new line) where certain criteria is met. In this case when there is an alphanumeric value following ),
pattern.
Something like this - but it is not quite working.
text_old =
some text some text
),
some text some text
), some text some text
which becomes -
text_format =
some text some text
),
some text some text
),
some text some text
text_format = text_old.lower().replace('), ^[a-zA-Z0-9_.-]*$','), \n')
Do I have the proper syntax here?
EDIT
I understand that replace
is not best approach for regex. So I have something like this, which isn't quite working -
re.sub(r'\),\s^\w+$','\), \n',text_old)
EDIT 2
I am very close, now it just cuts off the first letter it finds.
re.sub('\),\s\w','), \n',text_old)
Like this
text_format =
some text some text
),
some text some text
),
ome text some text
Where I would like it to find the pattern, not replace the first character