Reply To: Regsub cmd to replace multiple occurances

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Regsub cmd to replace multiple occurances Reply To: Regsub cmd to replace multiple occurances

#59419
Mike Grieger
Participant

    The ‘*’ being ‘greedy’ (as mentioned) is exactly what the issue is that you are having.  The way you have it written, it will only replace the LAST occurence in your test data, due to the greedy factor.

    adding the ? after the * makes the expression non-greedy, and works as you would want.

    (the letter ‘z’ is in there as it is easier to see than a space)

    set text “{DATE}{\fs24 }{\fs24 FIRST}{\fs24 }{\fs24 SEEN:}{\fs24 }{\fs24 }”

    echo $text

    regsub -all — {({B.*?)(s})} $text {1z2} text

    echo $text

    {DATE}{fs24 }{fs24 FIRST}{fs24 }{fs24 SEEN:}{fs24 }{fs24 }

    {DATE}{fs24z }{fs24 FIRST}{fs24z }{fs24 SEEN:}{fs24z }{fs24z }