Loading ...
Sorry, an error occurred while loading the content.

24024VanWeerthuizenian Expressions

Expand Messages
  • flo.gehrke
    Sep 10, 2013
      It has been discussed several times that NT doesn't master Boolean Expressions (cf message #21773). And we considered tools like DOS Findstr, Agent Ransack etc to be used in this case. It should also be mentioned that, to some extent, we could simulate Boolean Expressions with RegEx.

      Some years ago, Wayne VanWeerthuizen described another approach in his 'NoteTab Tutorial Control Structures v003.OTL' (see the 'File' section of this group).

      I picked up another topic (#22762) and tried to find a solution for that job based on instructions given by Wayne in his tutorial.

      Example: We've got five lines...

      tR4hGGUK
      2UJeiy9m
      WbNDSk9e
      Mytrip12
      My.tip12

      The task is to select lines which fulfill five criteria:

      (A) 8 characters
      (B) at least 2 upper characters
      (C) at least 2 lower characters
      (D) at least one digit
      (E) no punctuation characters or spaces

      According with Wayne's tutorial, I tried to translate his instructions to the following clip:

      ^!Set %Lines%=^$GetTextLineCount$
      ^!Set %Row%=1
      :Loop
      ^!Set %A%=0; %B%=0; %C%=0; %D%=0; %E%=0
      ^!Jump ^%Row%
      ; Condition #1: a string of 8 characters
      ^!If ^$StrPos("\b.{8}\b";"^$GetLine$";R)$>0 ^!Set %A%=1
      ; Condition #2: at least 2 upper characters in line
      ^!If ^$StrPos("[[:upper:]][[:alnum:]]*[[:upper:]]";"^$GetLine$";R)$>0 ^!Set %B%=1
      ; Condition #3: at least 2 lower letters in line
      ^!If ^$StrPos("[[:lower:]][[:alnum:]]*[[:lower:]]";"^$GetLine$";R)$>0 ^!Set %C%=1
      ; Condition #4: at least one digit in line
      ^!If ^$StrPos("[0-9]";"^$GetLine$";R)$>0 ^!Set %D%=1
      ; Condition #5: No punctuation characters or spaces in line
      ^!If ^$StrPos("[\x20\pP]";"^$GetLine$";R)$>0 ^!Set %E%=1
      ; Logical test of all criteria
      ^!If ^$Calc(MIN(^%A%;MIN(^%B;MIN(^%C%;MIN(^%D%;1-^%E%)))))$=1 Next Else Skip
      ; If whole expression is true then append line to %Hits%
      ^!Set %Hits%=^%Hits%^$GetLine$^P
      ^!Inc %Row%
      ^!If ^$GetRow$ < ^%Lines% Loop
      ; Output hits
      ^!Info [L]^%Hits%
      ^!ClearVariables

      Actually, this clip leads to the intended result and outputs line #1, #2, and #3 only, exactly matching those criteria. That is, the clip simulates a Boolean query like 'A and B and C and D and E and not E' reproduced with '^$Calc$'.

      Of course, this particular task might be resolved in easier ways. However, what matters here is this specific approach which - as Wayne explained - could apply to much more complex queries (with AND, OR, XOR, NOT etc). In cases like that, it would be difficult to use RegEx, and compound loops would end in extremely long "IF, ELSE IF, ELSE IF Chains" (Wayne).

      What I would like to know:

      Is anyone (also Wayne himself) still using such expressions and could give us more examples. Regrettably, Wayne's Tutorial was never finished and has remained a highly instructive fragment only. Also, it's lacking complete working examples.

      Regards,
      Flo
    • Show all 12 messages in this topic