python - Parse multi-line string up until first line with certain character -


i want parse out lines multi-line string until first line contains character- in case opening bracket.

s = """here lines  of text want. first line <tags> , after should stripped."""  s1 = s[:s.find('<')] s2 = s1[:s.rfind('\n')]  print s2 

result:

here lines
of text want.
first line with

what i'm looking for:

here lines
of text want.

change

s2 = s1[:s.rfind('\n')]  #this picks newline after "everything" 

to

s2 = s1[:s1.rfind('\n')]   

and work. there might better way though...


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -