Erinevus lehekülje "Itx8071-task1" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
 
(ei näidata sama kasutaja 112 vahepealset redaktsiooni)
1. rida: 1. rida:
 
This homework assignment requires the knowledge from Module 3.
 
This homework assignment requires the knowledge from Module 3.
  
Please write a regular expression for matching the sequence of numbers
+
==== Please write a regular expression for matching the sequence of numbers which follows these rules: ====
which follows these rules:
 
  
1) The sequence consists of one or more parts. If there are two or more parts,
+
* The sequence consists of one or more parts. If there are two or more parts, they are separated with a comma (",") character.
they are separated with a comma (",") character.
 
  
2) Each part of the sequence is a hexadecimal number which must contain the
+
* Each part of the sequence is either an integer or a real number. An integer number consists of one or more digits and must not begin with zero ("0"), unless the integer number has only one digit. If the part of the sequence is a real number, it consists of one or more digits which are followed by one dot (".") character, with this dot character being followed by one or more digits. Like the integer number, the real number must not begin with zero ("0"), unless there is only one digit before the dot character. Also, the real number must not end with zero ("0"), unless there is only one digit after the dot character.
following characters only: 0 1 2 3 4 5 6 7 8 9 0 A B C D E F a b c d e f.  
 
Each hexadecimal number must consist of even number of digits (for example,
 
2A, 1276, 1EA17C, 00A48390, etc.).  
 
Also, each hexadecimal number may be prefixed by an optional minus ("-") or
 
plus ("+") 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.
 
  
Examples of sequences the regular expression must match:
+
Please note that for accomplishing the task, '''one regular expression''' has to be submitted which is '''suitable for use with the egrep or pcre2grep 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.
  
* 123456              (the sequence has one valid hexadecimal number)
 
  
* 9A15,F3D50C          (the sequence has two valid parts)
+
==== Examples of sequences the regular expression must match: ====
  
* B1250022,-1754FF    (the sequence has two valid parts, with the second hexadecimal having a minus sign)
+
12345                (the sequence has one valid integer part)
  
* +81,-A20E17,0201    (the sequence has three valid parts, with the first hexadecimal having a plus sign and the second hexadecimal a minus sign)
+
915,2.35            (the sequence has two valid parts - an integer
 +
                      and a real number)
  
* C1,10,33,+411D8C,00,A0,-71,-80      (the sequence has eight valid parts)
+
1.205,754.0          (the sequence has two valid real number parts)
  
Examples of sequences the regular expression must NOT match:
+
8.4,12,0.1          (the sequence has three valid parts - a real number,
 +
                      integer, and a real number)
  
11, 22        (the second part begins with a space character which is illegal)
+
1,1.0,3,4.8,0.0,0,7.001,8.0      (the sequence has eight valid parts)
  
A 2,33        (the first part contains a space character which is illegal)
 
  
9A,            (the first part ends with comma, but there is no following second part)
+
==== Examples of sequences the regular expression must NOT match: ====
  
1G9A          (the number contains an illegal character G)
+
1, 2          (the second part begins with a space character which is illegal)
  
--F2          (the number begins with two minus signs, but only one sign is allowed)
+
1 2,3        (the first part contains a space character which is illegal)
  
2-1            (the minus sign illegally appears in the middle of a number)
+
9.0,          (the first part ends with comma, but there is no
 +
                following second part)
  
72,,89        (the second part of the sequence is empty)
+
9F            (the number contains an illegal character F)
  
12,-ABC,+84    (the second part does not consist of even number of hexadecimal digits)
+
02            (the integer number has more than one digit and begins with
 +
                a zero which is illegal)
  
P$12,43,22    (the sequence begins with illegal characters)
+
2.00          (the real number has more than one digit after the dot character
 +
                and ends with a zero which is illegal)
  
B2C3,12+T     (the sequence ends with illegal characters)
+
2-1          (the number contains an illegal character -)
 +
 
 +
2,,8.9        (the second part of the sequence is empty)
 +
 
 +
2.            (the real number contains a dot character without at least
 +
                one following digit)
 +
 
 +
.3            (the real number contains a dot character without at least
 +
                one preceding digit)
 +
 
 +
1.43.222     (the real number illegally contains two dot characters)

Viimane redaktsioon: 26. september 2023, kell 12:18

This homework assignment requires the knowledge from Module 3.

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

  • The sequence consists of one or more parts. If there are two or more parts, they are separated with a comma (",") character.
  • Each part of the sequence is either an integer or a real number. An integer number consists of one or more digits and must not begin with zero ("0"), unless the integer number has only one digit. If the part of the sequence is a real number, it consists of one or more digits which are followed by one dot (".") character, with this dot character being followed by one or more digits. Like the integer number, the real number must not begin with zero ("0"), unless there is only one digit before the dot character. Also, the real number must not end with zero ("0"), unless there is only one digit after the dot character.


Please note that for accomplishing the task, one regular expression has to be submitted which is suitable for use with the egrep or pcre2grep 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.


Examples of sequences the regular expression must match:

12345                (the sequence has one valid integer part)
915,2.35             (the sequence has two valid parts - an integer 
                      and a real number)
1.205,754.0          (the sequence has two valid real number parts)
8.4,12,0.1           (the sequence has three valid parts - a real number, 
                      integer, and a real number)
1,1.0,3,4.8,0.0,0,7.001,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)
02            (the integer number has more than one digit and begins with 
               a zero which is illegal)
2.00          (the real number has more than one digit after the dot character 
               and ends with a zero which is illegal)
2-1           (the number contains an illegal character -)
2,,8.9        (the second part of the sequence is empty)
2.            (the real number contains a dot character without at least
               one following digit)
.3            (the real number contains a dot character without at least
               one preceding digit)
1.43.222      (the real number illegally contains two dot characters)