Regular Expression Help

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Regular Expression Help

  • Creator
    Topic
  • #53413
    Keith McLeod
    Participant

      I need to replace either pattern in OBX:5.  Since this comes from different/many labs systems, I need it to work on either possibility.

      search for E.brE or .br and replace each occurence with ~.

      The .br expression works fairly easily but not having much luck on the E.brE expression.

    Viewing 5 reply threads
    • Author
      Replies
      • #77603
        David Barr
        Participant

          The patterns should be \E\.br\E\ and \.br\, but you can use (\E\.br\E\|\.br\) to match either one.

          If someone is sending you E.brE then they are doing something wrong.

        • #77604
          Keith McLeod
          Participant

            I would believe that what you sent would work, but this is what I get when actually using it.

            regsub -all {(\E\.br\E\|\.br\)} $xlateInVals {~} xlateOutVals

            E~E for the one with E contained in it, but works on the .br as you can see it replaced that pattern in the middle of the string.

            If I remove the |\.br\

          • #77605
            David Barr
            Participant

              You should probably replace $xlateInVals with [lindex $xlateInVals 0] seeing as how it’s a list being passed to a command that expects a string. I’m not sure if that’s the cause of the problem. Have you tried echoing out $xlateInVals to see what it looks like?

            • #77606
              Keith McLeod
              Participant

                Tried both of those.  No luck on it as of yet.

              • #77607
                Charlie Bursell
                Participant

                  I would try string map

                  First map all instances of .br to ~ and then all instances of E to “”

                  To make sure of the order do like

                  set inp [string map

                    [lindex $xlateInVals 0]]

                    set xlateOutVals

                      ]

                  • #77608
                    Keith McLeod
                    Participant

                      Here is what I ended up with so far until I can break it.

                      regsub -all {([\]+E[\]+.br[\]+E[\]+|\.br\)} [lindex $xlateInVals 0] {~} obx_5

                      set xlateOutVals

                        I may try Charlies as well and see how that goes…

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