regular expression help

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf regular expression help

  • Creator
    Topic
  • #48345
    Jennifer Shepard
    Participant

      Hi everyone,

      Our latest upgrade for our Mysis lab system has some funky sub id’s coming through, messing up my Xlate. I need a regular expression to take a sub id that is ZZ00.1 and only keep what’s after the period, which would be ‘1’ in this case. I hate to hardcode it looking for ZZ00. and then have the system throw me a different value.

      Thanks in advance,

    Viewing 2 reply threads
    • Author
      Replies
      • #58367
        John Perks
        Participant

          This can be done with tcl string and list manipulation.  Don’t forget, starting out, that your source value is really a list, and you want the first element of that list.  Depending on your tcl programming style, you can do it a couple of ways.

          You need to split the string (the first element of the xlateInVals list) on the . character, and get the last element of the resulting list.

          The following code will do it, and will work even if there are multiple or 0 occurences of the . character in the string.

          lindex [split [lindex $xlateInVals 0] .] [expr [llength [split [lindex $xlateInVals 0] .]] -1]

          Copy this code to your Pre TCL dialog box on the source side of the COPY action.

          To simplify your code, you could set a TCL variable to [lindex $xlateInVals 0] and reference that variable in your command string.  You can have multiple TCL command strings in your dialog box if they are separated by a semi-colon.

        • #58368
          Charlie Bursell
          Participant

            Assuming the pattern never shows up in the rest of the message, the following one line will work:

            set xlateOutVals [string map {ZZ00. {}} $xlateInVals]

          • #58369
            Jamin Gray
            Participant

              If you want to do this using a regular expression, I would suggest something like this:

              Code:


              regsub -all {ZZ00.(.*)} $var1 {1} var2

              where your original string is in $var1 and the result (everything after the period) will be put in $var2.

              The regex to match the pattern is ZZ00.(.*) which says look for ZZ00 followed by a period and then capture anything after the period.  Then you are taking that saved capture 1 and placing it in $var2.

              -jamin

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