regular expression

J

Johnathan Smith

hey

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

(e-mail address removed)

any help would be greatly appreciated

thanks
 
T

Thomas Adam

Hi --

hey

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

(e-mail address removed)

any help would be greatly appreciated

What is it you want to do with this?

a="(e-mail address removed)"
p "yes" if a.scan(/\w+\.(\w+\.)??(\w+)??\@(\w+)(.*)/).size > 0

And several other variations thereof.

-- Thomas Adam
 
B

Brian Candler

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

(e-mail address removed)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top