Thread: Regular Expression (Pattern Matching)

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Regular Expression (Pattern Matching)

    Hi all, am trying to interpret the following

    Code:
    if(!getEmail().matches("^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$"))
    {
                  errors.add("name",new ActionMessage("email.invalid") );
    }
    and my interpretation is
    Code:
    ^[a-zA-Z] must start with a letter(s)
    
    [\\w\\.-]* can be followed by  a number of characters including/ending with a dot or hyphen
    
    [a-zA-Z0-9]@ must have a letter(s) and should be followed by '@'
    
    [a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9] same as above (a string which may contain a dot or hyphen
    
    \\. a dot must exist 
    
    [a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$" a string which may contain a dot but must end with word characters
    Have a question, does these dots [\.] within brackets suggests that i can have dots in my address i.e [email protected] ?

  2. #2
    Registered User Kernel Sanders's Avatar
    Join Date
    Aug 2008
    Posts
    61
    Yes. It's saying that there are any number of strings made of letters, separated by '.'s

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. regular expression for matching XML
    By bling in forum Tech Board
    Replies: 4
    Last Post: 11-04-2008, 09:26 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM