I'm trying to remove a certain part of a string but currently not getting the correct answer. The string is:
new_text = "'Bob' is currently 'Absent'. Hi, my name is Matt. 'Bob' is currently 'Active'. Bob: Hey Matt"
I want the two substrings: 'Bob' is currently 'Absent'.
and 'Bob' is currently 'Active'.
to disappear. The name "Bob" may toggle between names with alphabetical and non-alphabetical characters. "Absent" and "Active" are two of the more common statuses displayed, however, I'd like to keep track of any string inside the single quotes.
This is the final sentence I want to return: Hi, my name is Matt. Bob: Hey Matt
.
Currently my code is:
re.sub(r"\'([\w\W\d]+)\' is currently \'[\w\W\d]+\'.\s", '', new_text)
And it's returning: Bob: Hey Matt
Can anyone help with this?