1

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.

1 Answer 1

3

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 ;.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.