How to remove part of the string after specific word in Python
Question: I get API-responses as a string which can be in two different formats:

1) `This is a message. <br><br>This message was created by Jimmy.`

2)

    
    
    This is a message.
    
    Text can be in the new row.
    
    This message was created by Jimmy.
    

I want to remove text "This message was created by ['name']" from every
message. Expected result:

> This is a message.

This is what I have tried:  
`modified_message = re.search('(.+?)<br><br>', message).group(1)`

It works with the 1) example, but it doesn't with 2) of course.

How could I filter the text off from 2) example as it is multiline string or
could it be possible with one expression?


Answer: Please check this. Added code to handle multiline strings.

    
    
    import re
    data1 = "This is a message. <br><br>This message was created by Jimmy."
    data2 = """
    This is a message.
    
    This message was created by Jimmy.
    """
    print "First case..."
    print data1
    output1 = re.findall('(.*?)This message was created',data1,re.DOTALL)[0].replace("<br>",'')
    print "Output is ..."
    print(output1)
    print "----------------------------------------"
    print "Second Case..."
    print data2
    print "Output is ..."
    output2 = re.findall('(.*?)This message was created',data1,re.DOTALL)[0].replace("<br>",'')
    print(output2)
    

Output:

    
    
    C:\Users>python main.py
    First case...
    This is a message. <br><br>This message was created by Jimmy.
    Output is ...
    This is a message.
    ----------------------------------------
    Second Case...
    
    This is a message.
    
    This message was created by Jimmy.
    
    Output is ...
    
    This is a message.
    

