Regsub – curly brace issue

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Regsub – curly brace issue

  • Creator
    Topic
  • #49535
    Ray Mullen
    Participant

    Hi,

    I have a translate that generates a hl7 message. Within the translate I have a few regsub commands that convert , to E | to F e.t.c and that works fine, however I have just encountered a problem when the user has entered a  ” { (Curly Brace) ” into the message, it plays havoc with the regsub.

    I prob need to replace the curly brace at the start, and then replace it back again before i release the message. I Have tried lots of different combinations but dont seem to be able to get the code to work, any one any ideas how to use regsub to replace a {.

    Thanks in advance

    Ray

Viewing 6 reply threads
  • Author
    Replies
    • #62357
      John Hamilton
      Participant

      Are you looking for something like this

      tcl>                                

      tcl>set CURLY “This is a {CURLY TEST}

      This is a {CURLY TEST} done          

      tcl>regsub -all “{” $CURLY “^$” STEP1

      1                                    

      tcl>regsub -all “}” $STEP1 “$^” STEP2

      1                                    

      tcl>echo $STEP2                      

      This is a ^$CURLY TEST$^ done        

      tcl>                                

      At least this should give you a start.  I’m sure if I worked at it we could get both brackets at the same time.

    • #62358
      Ray Mullen
      Participant

      Hi John , I have tried this code and it works fine from the command line but i can’t seem to get it to work within a translate ,  I have the following example but when i run it through the testing tool it gives me an error

      set c_output [lindex $xlateInVals 0]

      set a $c_output

      regsub -all “{” $a “^$” c_output

      set xlateOutVals

    • #62359
      Tom Rioux
      Participant

      Take this line:   regsub -all “{” $a “^$” c_output

      and change to: regsub -all “{” $a “^$” c_output

      Once I added the backslash, it worked fine in my test Xlate.

      Let me know how it works for you.

      Thanks….

      Tom Rioux

    • #62360
      John Hamilton
      Participant

      That is correct with in the Xlate you need to escape out the curly brackets.

      Also you may want to change “^$” “$^” to something a little more easy to deal with those both have special meaning and when you go to move the back to brackets it will be tough.  

      Maybe use “Cu_iN” and “Cu_ouT”  or something with out special characters.

    • #62361
      Ray Mullen
      Participant

      Thomas & John, thanks a million for you help , that worked just fine.

      Ray 😀

    • #62362
      Charlie Bursell
      Participant

      This would be much simplier and more egonomic if you used the string map command.

      tcl>                                

      tcl>set CURLY “This is a {CURLY TEST}

      set CURLY  [string map

        $CURLY]

        Regular expressions are powerful but not needed for every occasion.

    • #62363
      Ray Mullen
      Participant

      Ok Charlie , will try that out, thanks for your reply, appreciate it

      Ray

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

Forum Statistics

Registered Users
5,127
Forums
28
Topics
9,300
Replies
34,445
Topic Tags
288
Empty Topic Tags
10