regex - How to apply string method on regular expression in Python -
i'm having markdown file wich little bit broken: links , images long have line-breaks in it. remove line-breaks them.
example:
from:
see example [installation process ubuntu trusty](https://wiki.diasporafoundation.org/installation/ubuntu/trusty). project offers vagrant installation too, documentation admits know do, developer. if difficult ![https://diasporafoundation.org/assets/pages/about/network- distributed-e941dd3e345d022ceae909beccccbacd.png](data/images/network- distributed-e941dd3e345d022ceae909beccccbacd.png) _a pretty decentralized network (source: <https://diasporafoundation.org/>)_
to:
see example [installation process ubuntu trusty](https://wiki.diasporafoundation.org/installation/ubuntu/trusty). project offers vagrant installation too, documentation admits know do, developer. if difficult ![https://diasporafoundation.org/assets/pages/about/network-distributed-e941dd3e345d022ceae909beccccbacd.png](data/images/network-distributed-e941dd3e345d022ceae909beccccbacd.png) _a pretty decentralized network (source: <https://diasporafoundation.org/>)_
as can see in snippet, managed match links , images right pattern: https://regex101.com/r/ul8po4/2
but now, syntax in python use string method string.trim()
on have captured regular expression?
for moment, i'm stuck this:
fix_newlines = re.compile(r'\[([\w\s*:/]*)\]\(([^()]+)\)') # capture links , remove line-breaks urls # r'[\1](\2)'.trim() ?? post['content'] = fix_newlines.sub(r'[\1](\2)', post['content'])
edit: updated example more explicit problem.
thank answer
strip work similar functionality of trim. need trim new lines, use strip('\n'),
fin.readline.strip('\n')
Comments
Post a Comment