need regexp for "everything except"

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf need regexp for "everything except"

  • Creator
    Topic
  • #47878
    Kenadi Moore
    Participant

      This will be an easy one for you regexp pros, which I definitely am not…

      I need an regexp that will look at a string like to following:

      %label%Stuff that is here and different every time

      and return everything except %label%

      Thanks,

      Kenadi Moore

      OhioHealth

    Viewing 2 reply threads
    • Author
      Replies
      • #56966
        Bill Bertera
        Participant

          I think this is what you’re looking for:

          hcitcl>set a “%label%Stuff other than label”

          hcitcl>echo $a

          %label%Stuff other than label

          hcitcl>regexp {(%label%)(.*)} $a one two three

          1

          hcitcl>echo $three

          Stuff other than label

          hcitcl>

          [/b]

        • #56967
          Kenadi Moore
          Participant

            That works but can someone explain how the one two three part works in general.  I see the format for regexp is:

            regexp ?flags? pattern string ?match sub1 sub2 …?

            How do you know if there will be a sub1, sub2 etc and how do you know what they will represent?

            Thanks,

            Kenadi

          • #56968
            Bill Bertera
            Participant

              match will be the entire pattern that was matched.

              sub1, sub2, etc… will contain what is put in ().

              I put 2 pairs of (), so $one will be the entire pattern ($a), $two will contain %label%, and $three is the string you’re looking for. if there was another () with more of the pattern that would be $four (if ‘four’ was added to the command).

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