Using a null value as part of a regular expression.

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Using a null value as part of a regular expression.

  • Creator
    Topic
  • #49725
    Thomas Fortino
    Participant

    Hello Fellow Clovertechers,

       

      I’m trying to use an use the following regular expression in a tclproc to as part of if condition to continue a message. The values are IN and null {}. The regexp recognizes the IN but does not recognize the {} null.

    The regexp is below –

    if [regexp — IN|{} $vip] {

    I have tried escaping the {} using { } and “{}” but neither worked. I continue looking in the Brent Welch book but any help would be appreciated.

    AIX 5.1

    Platform V rev5.2

Viewing 5 reply threads
  • Author
    Replies
    • #63293
      Charlie Bursell
      Participant

      Tcl is iterpreting the {} as an empty string.  Pass the regular express to the parser with braces and Tcl will leave it alone.

      Try this:

      regexp — {IN|{}} $vip

      Works for me

    • #63294
      Chris Williams
      Participant

      regexp — {IN|^$} $vip

      Returns 1 for IN and null.

      Returns 0 for other non-null values.

      You need the curly braces surrounding the expression. The caret and dollar sign mark the beginning and end of a string (with nothing between them).

    • #63295
      Thomas Fortino
      Participant

      Thanks Charlie and Chris both examples worked great.

    • #63296
      Chris Williams
      Participant

      Thomas,

      Be aware of how you are representing a null string in your testing. Both regexp expressions will give you matches. However,

      ^$ will match a null (empty) string.

      00 will match a character that is a null.

      {} will match a pair of curly brace characters.

    • #63297
      Charlie Bursell
      Participant

      What Chris is saying is true.  I was under the assumption you want to match a literal pair of braces

    • #63298
      Thomas Fortino
      Participant

      Thank, I used Chris’s code because I was looking for a null value. I tested the using both “IN” and a empty field in the data.

      regexp — {IN|^$} $vip

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

Forum Statistics

Registered Users
5,074
Forums
28
Topics
9,252
Replies
34,241
Topic Tags
275