Here is my string '2018-01-31 05:29:37 | Jan Pong Lee | [Number of contacts]:1'
I would like to remove '| Jan Pong Lee |'. The name can have 2 or 4 words, is there a way to do that?
Here is my string '2018-01-31 05:29:37 | Jan Pong Lee | [Number of contacts]:1'
I would like to remove '| Jan Pong Lee |'. The name can have 2 or 4 words, is there a way to do that?
You can use this regex to match and replace it with empty string,
\|[^|]*\|
Explanation of this regex: This regex basically captures a | followed by any character (except |) zero or more times and finally captures a | character and then stops capturing and replaces all matched characters with empty string.
Here is the python code for same,
import re
s = '2018-01-31 05:29:37 | Jan Pong Lee | [Number of contacts]:1'
ret = re.sub(r'\|[^|]*\|', '', s)
print (ret)
Which prints the remaining string after removal of | Jan Pong Lee |. This will work no matter whatever number of words you have inside those pipes.
2018-01-31 05:29:37 [Number of contacts]:1