i have a sh file, i need my python script to find specific strings and replace all the text between them in it:
hello_example=( # <- this specific line
"bla"
"bla"
"bla"
"bla"
"bla"
) # <- until this one
i already have the correctly formatted string to replace this with, i just didnt found an effective way to do what i just described so far.
What would be the best solution?
CodePudding user response:
Try this: check solution here: Regex101
your_input = """hello_example=(
"bla"
"bla"
"bla"
"bla"
"bla"
)"""
re.sub(r"(?<=hello_example\=\().*(?=\))", '', your_input, flags=re.S)
Output:
'hello_example=()'