Jamin Gray

Forum Replies Created

Viewing 9 replies – 1 through 9 (of 9 total)
  • Author
    Replies
  • in reply to: negative lookahead Regular Expression #60361
    Jamin Gray
    Participant

      Could you post the regex line in your tcl code?  I can’t duplicate the problem in hcitcl

      Code:


      hcitcl>set x R01MDOC
      hcitcl>regexp {R01(?!MDOC)} $x match
      0

      hcitcl>set x R01GENLAB
      hcitcl>regexp {R01(?!MDOC)} $x match
      1

      Seems to be working….

      in reply to: Regular Expressions #60322
      Jamin Gray
      Participant

        Code:


        regsub {(NOTE:)(d{2}/d{2}/d{2})?)} $x {~} x

        where $x is your string.  This one is a bit more specific about the pattern, looking for the optional date instead of just any text.  And it illustrates the escape in the replacement which evaluates to all of the match.

        in reply to: datetime regexpression help #59584
        Jamin Gray
        Participant

          If you want to just use a regsub:

          Code:


          regsub {(d{4})(d{2})(d{2})(d{4})d{2}} $date {2/3/1, 4 Hours} date

          in reply to: Regsub cmd to replace multiple occurances #59418
          Jamin Gray
          Participant

            One problem is that .* is greedy.  It will match the largest possible string that matches the pattern.

            What about this?

            Code:


            regsub -all {({\.{4} )(})} $text {1 2} text

            It captures a { follwed by a followed by 4 characters followed by a space.  then it captures the closing } and puts them together with a space between them.  

            Result:

            Code:


            hcitcl>regsub -all {({\.{4} )(})} $text {1 2} text2
            2
            hcitcl>puts $text
            DATE}{fs24 }{fs24 FIRST}{fs24 }{fs24 SEEN:}
            hcitcl>puts $text2
            DATE}{fs24  }{fs24 FIRST}{fs24  }{fs24 SEEN:}

            in reply to: Stripping non-alphabetic characters out of a field #56186
            Jamin Gray
            Participant

              Robert Milfajt wrote:

              regsub -all {[^A-Z,a-z]} $x “” y

              ought to do the trick, where x is the input string and y is the output string.

              Hope this helps,

              Bob

              This will also leave commas in the field.  If the system barks at anything but alphas you might want to change it to:

              Code:


              regsub -all {[^A-Za-z]} $x {} y

              or

              Code:


              regsub -all -nocase {[^a-z]} $x {} y

              in reply to: Removing All Double Quotes from a Message #58768
              Jamin Gray
              Participant

                In a tps tcl proc you could do:

                Code:


                regsub -all {”} $msg {} msg

                in reply to: regexp and null #58633
                Jamin Gray
                Participant

                  If by null you mean an empty string, you don’t need a regular expression to test this.  You could use the string equal command:

                  Code:


                  string equal $iam_18 “”

                  will return 1 if $iam_18 is “” otherwise it’ll return 0

                  If you really want to use a regular expression:

                  Code:


                  regexp {^$} $iam_18

                  I think what your code is doing is checking if the string matches the null character (octal 0 on the ASCII chart), not checking to see if the string is empty.

                  in reply to: Regular Expressions #58535
                  Jamin Gray
                  Participant

                    I may be misunderstanding your question, but if you’re looking for a regular expression that matches all three of the example lines you list, how about this?

                    Code:


                    regexp — {”d+”,(”[w ,]+”)?,”[w ]+”} $test

                    It matches 1 or more digits enclosed in double quotes followed by a comma, followed by an optional string of word characters/spaces/commas enclosed in double quotes followed by a comma, followed by a string of word characters or spaces enclosed in double quotes.  It returns true for all three of the examples you listed.

                    -jamin

                    in reply to: regular expression help #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 9 replies – 1 through 9 (of 9 total)