0

I have string like this:

text = "bla bla bla\n {panel:title=Realisation|borderStyle=dashed|borderColor=#cccccc|titleBGColor=#a39d9d}\n bla bla bla\n {panel:title=Definition of Done|borderStyle=dashed|borderColor=#cccccc|titleBGColor=#a39d9d} bla bla

and i need replace {panel:title=Realisation|borderStyle=dashed|borderColor=#cccccc|titleBGColor=#a39d9d} to Realisation and {panel:title=Definition of Done|borderStyle=dashed|borderColor=#cccccc|titleBGColor=#a39d9d} to Definition of Done

I tried to do it like this

def del_tags(text):
    if text:
        CLEANR = re.compile('{panel.*?}')
        try:
            TITLES = re.search('title\=(.+?)\|', text).group(1)
        except AttributeError:
            TITLES = ""
        cleantext = re.sub(CLEANR, TITLES, text)
        return cleantext
    else: 
        return text

But they replace everything with Realisation.

How can I solve my problem?

0

1 Answer 1

1

Try:

import re

text = "bla bla bla\n{panel:title=Realisation|borderStyle=dashed|borderColor=#cccccc|titleBGColor=#a39d9d}\nbla bla bla\n{panel:title=Definition of Done|borderStyle=dashed|borderColor=#cccccc|titleBGColor=#a39d9d} bla bla"

text = re.sub(r"{panel:title=([^|}]+).*?}", r"\1", text)
print(text)

Prints:

bla bla bla
Realisation
bla bla bla
Definition of Done bla bla

{panel:title=([^|}]+).*?} will match title after the panel:title= and substitute the whole {...} - regex101

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.