Regular Expression Help

Discussion in 'Perl Misc' started by TechStu, Dec 15, 2004.

  1. TechStu

    TechStu Guest

    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!
     
    TechStu, Dec 15, 2004
    #1
    1. Advertisements

  2. --^^^^^^^^^^^^^
    Stopped reading here.
     
    Gunnar Hjalmarsson, Dec 15, 2004
    #2
    1. Advertisements

  3. TechStu

    Peter Wyzl Guest

    :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";
     
    Peter Wyzl, Dec 15, 2004
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.