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
Post a Comment