From: Brian Candler Date: 2010-11-07T00:34:46+09:00 Subject: Re: regular expression Johnathan Smith wrote in post #616840: > im looking to write a regular expression for an email address > however, i want the first part of the name to be initials (first initial > and optional middle initial) and a surname > > such as > > j.m.smith@domain.com Is this a homework question? Break the problem down. Write regexp expressions which match the individual bits: * any letter followed by a dot * a surname - say any sequence of one or more letters * an @ sign * a domain (depends how strict you want to be - maybe sufficient is to match letter, digit, dot or hyphen, one or more times) and then combine them. To match any letter, use a range: [a-z] To match a literal dot, use \. (because . matches any character) To match something 0 or 1 times, follow it by '?' To match something 0 or more times, follow it by '*' To match something 1 or more times, follow it by '+' Use parentheses to make a group - e.g. the way to match the optional middle initial is (xxx)? where xxx is whatever regexp you chose to match a letter followed by a dot HTH, but if it doesn't, find a good regexp primer. Regards, Brian. -- Posted via http://www.ruby-forum.com/.