regsub again

  • Creator
    Topic
  • #50242
    Andrew Deters
    Participant

    in the following command

    regsub -all {^US|} $msg {^USA|} outbuf

    Should i escape the ^ and the | in {^USA|}???

Viewing 3 reply threads
  • Author
    Replies
    • #65307

      Andrew Deters wrote:

      in the following command

      regsub -all {^US|} $msg {^USA|} outbuf

      Should i escape the ^ and the | in {^USA|}???

      That depends on what you’re trying to do. In this case I assume the ^ is part of the data (i.e., you’re not using it to mean the beginning of the line), so yes you have to escape them in the first set of braces. You can’t escpate them in the second set of bracers (the replacement).

      Code:

      set msg “test test test^US^foo bar”
      regsub -all — {^US} $msg {^USA} outbuf
      puts $outbuf

      -- Max Drown (Infor)

    • #65308
      Andrew Deters
      Participant

      I am hoping to change ^US| to ^USA|

    • #65309

      Andrew Deters wrote:

      I am hoping to change ^US| to ^USA|

      Code:

      regsub -all — {^US|} $msg {^USA|} outbuf

      -- Max Drown (Infor)

    • #65310
      Charlie Bursell
      Participant

      regsub is not always the best tool.  Try string map instead

      set map

        set var [string map $map $var]

Viewing 3 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,125
Forums
28
Topics
9,294
Replies
34,439
Topic Tags
287
Empty Topic Tags
10