Announcement

Collapse
No announcement yet.

Regular Expressions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regular Expressions

    Hey all! I'm searching through text data (using regular expressions)
    and searching for SMTP error codes. I've commented some code below
    to highlight what I'm experiencing. I figure posting the code with
    comments would be easier than explaining without the code. Any help
    would be HIGHLY appreciated.
    Thanks! -Scott

    Code:
    $COMPILE EXE
    
    
    FUNCTION PBMAIN() AS LONG
    
        LOCAL strMessage     AS STRING
        LOCAL a              AS STRING
        LOCAL b              AS STRING
    
        
        
        'NOTE:  This a$ does not work.  Note position of - symbol.
        'I'm assuming this doesn't work because it's being interpreted
        'as a range between the _ and ~.
        'a$ = "[a-z0-9._-~][email protected][a-z0-9._-~]+"
    
    
        'NOTE: How come this doesn't work?  I'm escaping the - symbol.
        'Is it okay to escape characters within a character class?  Seems
        'like it *should* work.
        'a$ = "[a-z0-9._\-~][email protected][a-z0-9._\-~]+"
        
        'NOTE: Moved the minus sign to the end of each character class
        'and everything seems to work fine.
        a$ = "[a-z0-9._~-][email protected][a-z0-9._~-]+"
        
        'NOTE: Do I need to escape the . in a character class?  Doesn't
        'seem to make a difference.
        'a$ = "[a-z0-9\._~-][email protected][a-z0-9\._~-]+"
    
    
        
        
        b$ = "550 5\.1\.1 <" & a$ & "> is NOT a valid mailbox"
    
        strMessage$ = "Diagnostic-Code: smtp;550 5.1.1 <[email protected]> is not a valid mailbox"
        REGEXPR b$ IN strMessage$ TO lPosition&, llength&
    
        MSGBOX STR$(lPosition&) & ":" & strMessage$
       
    END FUNCTION
    ------------------




    [This message has been edited by Scott Wolfington (edited September 06, 2000).]
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

  • #2
    Hi Scott

    PB regular expression don't support escaped characters in
    character classes. The "-" sign is a range operator so that
    placing it in the middle of a character class as in:

    [a-z0-9.-~]

    is interpreted as "all alphanumeric with characters ranging from
    "." to "~"" which will give incorrect results.

    As you found out, placing the "-" last means that the expression
    is correctly evaluated. Character class meta-characters placed first
    or last in a character class are usually evaluated as literals
    since they otherwise make no sense.

    So:

    [a-z0-9.~-]

    and

    [-a-z0-9.~]

    will give equivalent results.

    Cheers

    Florent




    [This message has been edited by Florent Heyworth (edited September 07, 2000).]

    Comment


    • #3
      Thanks Florent! I really appreciate your help.

      Regards,
      Scott
      :-)



      ------------------
      Scott Wolfington
      [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

      Comment

      Working...
      X