Slicing
If the format of the string doesn't change you can slice the string as follows:
string = "Engine NOrc04/14/20 11:24XX5555-May-2021"
new_string = string[:11] + string[25:]
print(new_string)
string = "Engine NOrc04/14/20 11:24XX5555-May-2021 report contains below information..."
new_string = string[:11] + string[25:]
print(new_string)
Output
Engine NOrcXX5555-May-2021
Engine NOrcXX5555-May-2021 report contains below information...
Using regex
If the time appears in different parts of the string, but the format of the time doesn't change, you can use re.sub()
to replace the time string:
import re
string = 'Engine NOrc04/14/20 11:24XX5555-May-2021 report contains below information...'
new_string = re.sub('\d\d/\d\d/\d\d \d\d:\d\d', '', string)
print(new_string)
string = 'SOME OTHER RANDOM STRING 04/14/20 11:24 THIS IS A DIFFERENT STRING'
new_string = re.sub('\d\d/\d\d/\d\d \d\d:\d\d', '', string)
print(new_string)
Output:
Engine NOrcXX5555-May-2021 report contains below information...
SOME OTHER RANDOM STRING THIS IS A DIFFERENT STRING