Reputation: 59
I have string something like this
mystring = "CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\n*options; mprint ls=max mprint;\n\n****************************************out; asd; ***hg;"
I want to delete the string between * and ; output should be
"CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\ mprint ls=max mprint;\n\n asd;"
I have tried this code
re.sub(r'[\*]*[a-z]*;', '', mystring)
But it's not working.
Upvotes: 1
Views: 75
Reputation: 626699
You may use
re.sub(r'\*[^;]*;', '', mystring)
See the Python demo:
import re
mystring = "CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\n*options; mprint ls=max mprint;\n\n****************************************out; asd; ***hg;"
r = re.sub(r'\*[^;]*;', '', mystring)
print(r)
Output:
CBS Network Radio Panel;
title2 New York OCT13W4, Panel Weighting;
mprint ls=max mprint;
asd;
The r'\*[^;]*;'
pattern matches a literal *
, followed with zero or more characters other than ;
and then a ;
.
Upvotes: 3