How to replace non-character surrounded string in python

I have a variable with a collection of arguments (newArgs), I want to replace any occurrence of a certain string inside this variable. I can get into my if condition using the command:

if (, newArgs) ):

the ‘if’ condition wont do anything if the condition found the exact item inside the newArgs

when it enters the ‘else’ condition, it should trigger the re.sub command:

Not working:

newArgs = re.sub(argVariable+’=r(S*S)?’, item, newArgs)

Note: I can get the ‘argVariable’ which in this sample valued as “-Dweblogic.Stderr”

How can I replace the matching string with the new ‘item’ inside the ‘newArgs’?

Sample string to be replaced:


I want to search anything beyond the = sign and it will stop until it sees a whitespace (because going beyond the whitespace is for the next argument) or if it is the end of the newArgs variable

I want it to be replaced with something like:


Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.