Itx8071-task1

Allikas: Kursused
Redaktsioon seisuga 26. september 2018, kell 12:51 kasutajalt Risto (arutelu | kaastöö)
Mine navigeerimisribale Mine otsikasti

This homework assignment requires the knowledge from Module 3.

Please write a regular expression for matching the sequence of hexadecimal 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 a non-zero hexadecimal number which must contain the following characters only: 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f. Each hexadecimal number must consist of odd number of hexadecimal digits and must not begin with 0 (for example, 2A1, 10276, 71EA17C, 500A48390, etc.). Also, each hexadecimal number may be prefixed by 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 programs in Java, Python, Perl (or any other language) 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:

1234567 (the sequence has one valid hexadecimal number) 
9A150,F3D50C3 (the sequence has two valid parts) 
B125022,-174FF (the sequence has two valid parts, with the second hexadecimal having a minus sign) 
-281,-A2E17,201 (the sequence has three valid parts, with the first and second hexadecimals having a minus sign) 
C,1,3,41D8C,1,A,-71A,-180 (the sequence has eight valid parts) 


Examples of sequences the regular expression must NOT match:

110, 220 (the second part begins with a space character which is illegal) 
1A 2,337 (the first part contains a space character which is illegal) 
9A1, (the first part ends with comma, but there is no following second part) 
1G9A2 (the number contains an illegal character G) 
-09A (the number starts with a 0)
011 (the number starts with a 0)
--F (the number begins with two minus signs, but only one sign is allowed) 
12-1 (the minus sign illegally appears in the middle of a number) 
172,,189 (the second part of the sequence is empty) 
121,-AB,D8 (the second and third part do not consist of odd number of hexadecimal digits) 
P$121,4D3,B22 (the sequence begins with illegal characters) 
B2C,312+T (the sequence ends with illegal characters)