Regexp help

  • Creator
    Topic
  • #52657
    Alka Sharma
    Participant

      Good Morning,

      I have an OBX which looks like below:

      OBX|1|ST|RPT-0002^Paceart PDF File Location|1|C:EPaceartEExportE�1-08-23T09-21-04 Name=ALLETSON GUID={E8FE8E13-7A3E-4606-BCCE-DACD4D5FD553}.pdf|’

      I need to pull out the value of the GUID which is “E8FE8E13-7A3E-4606-BCCE-DACD4D5FD553”

      I started doing this with regexp but was unable to do it . So this is what I did to grab the value:

      set Obxlist [split $lastobx $fsep]

      set obx5 [string trimleft [string trimright [lindex [split [lindex [split [lindex [split [lindex $Obxlist 5] ] 2] =] 1] .] 0] }] {]

      I would like to know how to achieve the same result using regular expressions. Appreciate any help from regexp experts.

      Thanks Alka

    Viewing 17 reply threads
    • Author
      Replies
      • #75017
        Keith McLeod
        Participant

          Not sure wheree you are starting from but something like this may help.

          using the field as the source and something like this as a preproc.

          This will match GUID={ and then (not a right curly brace) between the parentheses.  The ‘–>’ is just a variable name for the complete match and the 1 or match of what’s between the parentheses goes into xlateOutVals

          regexp — {GUID={([^}]+)} [lindex $xlateInVals 0] –> xlateOutVals

          Hope this helps….In between the parentheses is one or more characters that is not a right curly brace…..

        • #75018
          Charlie Bursell
          Participant

            Works fine but will give you fits if there happens to be a space in the field or the regexp does not match.

            There is also no need to escape the braces

            I would do it like:

            if {[regexp — {GUID={([^}]+)} [lindex $xlateInVals 0] {} var]} {

                    set xlateOutVals

              }

              This way if the regexp does not match xlateOutVals will be equal xlateInVals

          • #75019
            Keith McLeod
            Participant

              Thanks Charlie.  It is much cleaner and handles those pesky spaces better.

            • #75020
              Keith McLeod
              Participant

                I have an application where I can only enter a regular expression.  I need to exclude only one value but have found it to be challenging.  I want all numbers except one. I thought I could use something like lookahead 20 and don’t match if next character is an 8 with no additional following characters(digits). Any help would be appreciated.

                Let’s say 208 so I need to include everything except 208.

                (?:0d*|1d*|2ds+|20[0-79]|20[0-79]d+|208d+|2[1-9][0-9]d*|3d*|4d*)

              • #75021
                Charlie Bursell
                Participant

                  Confusing Keith.

                  Is it always the last number to exclude.  Will these numbers be embedded in a string?  Is there a better example?

                • #75022
                  Keith McLeod
                  Participant

                    They are code values so the text will include

                    ERROR

                    or

                    ERROR-

                    I am aware that numbers could be up to 4 digits so far.

                  • #75023
                    Charlie Bursell
                    Participant

                      Are you saying you want the whole string unless the number is 208?

                    • #75024
                      Keith McLeod
                      Participant

                        Yes

                      • #75025
                        Keith McLeod
                        Participant

                          ERROR-20 would also be valid.

                        • #75026
                          Charlie Bursell
                          Participant

                            Then can’t you say something like:

                            if {[regexp -nocase — {ERROR-208} $str] {

                                 set ERR “”

                            } else {

                                 set ERR $txt

                            }

                            Am I missing something?

                          • #75027
                            Keith McLeod
                            Participant

                              Unfortunately, I can only enter a regular expression.

                            • #75028
                              Charlie Bursell
                              Participant

                                Hmmm  have to think about that

                              • #75029
                                Charlie Bursell
                                Participant

                                  A negative look ahead seems to work for me

                                  {ERROR-(?!208).*$}

                                  Will match any string with ERROR-#### some text except when it is 208

                                  If you need more send me an e-mail.  No need to fo back and forth here 🙂

                                  charlie.bursell@laswon.com

                                • #75030
                                  Keith McLeod
                                  Participant

                                    If I have 20 and the next digit is 8 and a word boundary, don’t match.  If I have 208 and more digits, do match.  Haven’t figured out how to write that yet….

                                  • #75031
                                    Charlie Bursell
                                    Participant

                                      {ERROR-(?!208M).*$}

                                    • #75032
                                      Keith McLeod
                                      Participant

                                        Thanks…  I think that last one might do it.

                                      • #75033
                                        Terry Kellum
                                        Participant

                                          Charlie, would you be willing to do a class on Regular Expressions??

                                          That might be worth the outrageous price for the yearly user group…

                                        • #75034
                                          Charlie Bursell
                                          Participant

                                            I cover regular expressions in Level 3 although maybe not to the detail you want.

                                            There are a *LOT* of regular expression tutorial on the web

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