regexp to search a string

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf regexp to search a string

  • Creator
    Topic
  • #48276
    Henry Bauer
    Participant

      I would like to use regexp to search a string in a free text comment field for the entires tba or TBA or aop or AOP. These entries can be entered with a / or – or blank space preceding them. I have tried the example regexp {^(tba|TBA|aop|AOP)$} $comment but I am unsure how to extract if it is there inside of a tcl script. I want to know if it is there and place that entry into another field for one of our downstream systems. Any help would be gratly appreciated. Thanks

    Viewing 1 reply thread
    • Author
      Replies
      • #58235
        Steve Carter
        Participant

          It should be as simple as adding a variable to the end of your regexp.

          $  set comment “this is an aop type comment”

          $  regexp {(tba|TBA|aop|AOP)} $comment output

          $  1

          $  puts $output

          $  aop

          This is assuming you don’t want the – / or blank space returned.  You may also want to drop the ^ and $ from your regexp unless the string will only contain one of the four values.

          Hope this helps.

          Steve

        • #58236
          Charlie Bursell
          Participant

            Better still:

            set val “”; regexp -nocase {(TBA|AOP)) $str val

            If either value is there, val is set to the value, else val is the empty string

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