Replace everything between 2 characters?

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Replace everything between 2 characters?

  • Creator
    Topic
  • #52760
    Tim Hallbauer
    Participant

      Hi Clovertechers,

      I need to replace all characters which appear between a “< " and a ":" yet maintain the data that follows after the ":".  I can get it to the point where it strips it out, but the data following is lost? regsub -all — {<.*:} $msgdata "" newMsg example

      THX

      Tim

    Viewing 2 reply threads
    • Author
      Replies
      • #75406
        Daniel Lee
        Participant

          Try this:

          Code:

          regsub -all — {<.*?:} $msgdata "" newMsg

          I think the problem is the ‘*’ is a greedy search.  The way you had it the code would try to match from the very first ‘<' in the data to the very last ':' in the data.  I looks like you want a lazy search that when it finds the first '<' it will stop at the very first ':' it finds.  The '?' above will cause it to not do a lazy search instead of a greedy search.

        • #75407
          Keith McLeod
          Participant

            Can a : be included in the data?

            <abc:de: for example?

            If not you may try something like

            regsub -all — {<[^:]+:} $msgdata {} newMsg

            Do you still want the <: in the newMsg?

            If so you would need to add that back in…

            Can you provide a more complete example?

          • #75408
            Tim Hallbauer
            Participant

              Thanks, I tried Daniel’s suggestion and it worked like a charm. I was missing the “?” .

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