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

#59418
Jamin Gray
Participant

    One problem is that .* is greedy.  It will match the largest possible string that matches the pattern.

    What about this?

    Code:


    regsub -all {({\.{4} )(})} $text {1 2} text

    It captures a { follwed by a followed by 4 characters followed by a space.  then it captures the closing } and puts them together with a space between them.  

    Result:

    Code:


    hcitcl>regsub -all {({\.{4} )(})} $text {1 2} text2
    2
    hcitcl>puts $text
    DATE}{fs24 }{fs24 FIRST}{fs24 }{fs24 SEEN:}
    hcitcl>puts $text2
    DATE}{fs24  }{fs24 FIRST}{fs24  }{fs24 SEEN:}