Ics0020-task1

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti

This homework assignment requires the knowledge from Module 3.

Please write a regular expression for matching the sequence of numbers which follows these rules:

1) The sequence consists of one or more parts. If there are two or more parts, they are separated with a comma (",") character.

2) Each part of the sequence is either an integer or a real number. An integer number consists of one or more digits and may begin with an optional minus ("-") sign. If the part is a real number, it consists of one or more digits which are followed by one punctuation mark ("."), with this punctuation mark being followed by one or more digits. Like integer number, the real number may begin with an optional minus ("-") sign.


Please note that for accomplishing the task, one regular expression has to be submitted which is suitable for use with the egrep or pcregrep tool. It is not acceptable to submit the solution in a fragmented way (e.g., several isolated expressions for addressing different parts of the task). Also, it is not allowed to submit Java-based, Python-based, Perl-based, or any other programs for the solution. Finally, if the solution only works with the examples provided below but does NOT meet the task specification, it will be treated as incorrect.


Examples of sequences the regular expression must match:

012345               (the sequence has one valid integer part)
915,2.35             (the sequence has two valid parts - an integer and real number)
1.25,-754            (the sequence has two valid parts - a real number and negative integer number)
-8.4,-12,0.1         (the sequence has three valid parts - a negative real number, a negative integer, and a real number)
1,1.0,3,4.8,0.0,0,-7.1,-8.0      (the sequence has eight valid parts)


Examples of sequences the regular expression must NOT match:

1, 2          (the second part begins with a space character which is illegal)
1 2,3         (the first part contains a space character which is illegal)
9.0,          (the first part ends with comma, but there is no following second part)
9F            (the number contains an illegal character F)
--2           (the integer number begins with two minus signs, but only one sign is allowed)
2-1           (the minus sign illegally appears in the middle of a number)
2,,8.9        (the second part of the sequence is empty)
-2.           (the real number contains a punctuation mark without at least one following digit)
.3            (the real number contains a punctuation mark without at least one preceding digit)
1.43.222      (the real number illegally contains two punctuation marks)