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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -