Regular Expression Help

T

TechStu

I need help writing regular expressions for the following problems:-

1. date has the following format: month day, year
month is a name of the month,
day represents a day and may contain one or two digits,
y represents a year and contains 4 digits.
Your solution (regular expression) should match, for example, the
following:
July 4, 2004
September 16,1987
December 3, 2001
However, your solution (regular expression) should not match, for
example, the
following:
Dec 3, 2001
February 30, 2002
2. file name has the following format:
disk-drive:\directory-name\...\directory-name\name.extension
disk-drive is a letter that indicates a disk drive
directory-name represents a directory name that starts with a letter
and contains letters,
digits, or '_' characters. The maximum size of directory-name is 16.
name represents a file name that starts with a letter and contains
letters, digits, or '_'
characters. The maximum size of name is 16.
extension represents a file type. The following file types should be
considered: exe, pdf,
doc, xls, txt.
Your solution (regular expression) should match, for example, the
following:
search1.exe
c:paper.pdf
c:\paper.pdf
a:\class\cs763\fall_2004\syllabus.doc

However, your solution (regular expression) should not match, for
example, the
following:
c:paper.xxx

Thanks!
 
G

Gunnar Hjalmarsson

TechStu said:
I need help writing regular expressions for the following problems:-

1. date has the following format: month day, year
month is a name of the month,
day represents a day and may contain one or two digits,
y represents a year and contains 4 digits.
Your solution (regular expression) should match, for example, the
--^^^^^^^^^^^^^
Stopped reading here.
 
P

Peter Wyzl

:I need help writing regular expressions for the following problems:-
:
: 1. date has the following format: month day, year
: month is a name of the month,
: day represents a day and may contain one or two digits,
: y represents a year and contains 4 digits.
: Your solution (regular expression) should match, for example, the
: following:
: July 4, 2004
: September 16,1987
: December 3, 2001
: However, your solution (regular expression) should not match, for
: example, the
: following:
: Dec 3, 2001
: February 30, 2002

Why the hell would anyone teach you to use a regex for that? String
extraction and date validation should properly be handled separately, there
being good modules to handle the latter. Go give your teacher a smacking...

P
print "What homework?\n";
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top