regex - How to write regular expression to use re.split in python -
i have string this:
---------- ft weekend ---------- why run marathons? marathons , cycling races more exercise? literature of endurance tell our thirst self-imposed hardship?
i want delete part ----------
next ----------
included.
i have been using re.sub
:
pattern =r"-+\n.+\n-+" re.sub(pattern, '', thestring)
pattern =r"-+\n.+?\n-+" re.sub(pattern, '', thestring,flags=re.dotall)
just use dotall
flag.the problem regex default .
not match \n
.so need explicitly add flag dotall
making match \n
.
see demo.
https://regex101.com/r/hr7th4/24
or
pattern =r"-+\n[\s\s]+?\n-+" re.sub(pattern, '', thestring)
if dont want add flag
Comments
Post a Comment