Erinevus lehekülje "Itx8071-task1" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
 
(ei näidata sama kasutaja 45 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 software module names and optional version numbers, so that the sequence will follow these rules: ====
+
=== Please write a regular expression for matching the sequence of integer expressions 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.
+
1) The sequence consists of one or more elements. If there are two or more elements, they are separated with a comma (,) character.
  
* Each part of the sequence is a software module name which is optionally followed by a version number. If the version number is present, there must be a dash ("-") character between the software module name and the version number. If there is no version number, the use of dash character after the software module name is not permitted.
+
2) Each element of the sequence is an expression that can consist of digits 0 1 2 3 4 5 6 7 8 9 and the plus (+), minus (-), asterisk (*), and slash (/) characters. No other characters (such as spaces or letters) are permitted in the element. The element must contain one or more integer numbers, where the integer number is defined as a non-empty sequence of digits. If the element has more than one integer number, two consecutive integer numbers must be separated with a single plus, minus, asterisk or slash character. If the asterisk or slash separates two integer numbers, an optional minus (-) character can appear before the second (right-hand side) integer number. However, if two integer numbers are separated by plus or minus character, the minus prefix is not allowed for the second integer. Also, an optional minus (-) character can appear before the first integer number in the element (in other words, the first character of the element can be either a minus or a digit).
  
* Software module name must contain at least one character and must begin with a letter, and may contain letters and digits only.
+
For example, the following are valid sequence elements:
  
* The version number consists of one or more elements. If there are two or more version number elements, these elements must be separated with a dot (".") character. Note that the dot character may not appear before the first or after the last element. Each version number element must be a sequence of one or more digits which may be optionally followed by one letter.
+
012
 +
-1
 +
2+3
 +
-0+12-7
 +
22+90*-2/60
 +
-100+16/-2*-30
  
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'''.
+
However, the following sequence elements are invalid:
  
==== Examples of sequences the regular expression must match: ====
+
1 + 2 (the space character appears both before and after the plus character, but the use of spaces is illegal)
 +
1%2 (an illegal character % appears between two integer numbers)
 +
12C (an illegal character C appears after the integer number)
 +
12--2 (if the minus character separates two integer numbers, it is not allowed to use the minus prefix for the second integer)
  
m4-1.4.16
+
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. Finally, if the solution only works with the examples provided below but does NOT meet the task specification, it will be treated as incorrect.
(the sequence has one valid part -- a software module name with a version number of 3 elements)  
 
  
coreutils,pcre-8.32
+
=== Examples of sequences the regular expression must match: ===
(the sequence has two valid parts -- note that the first part does not have a version number)
 
  
  libtasn1-4.09a,GeoIP-1.5.0,iwl6000g2a
+
  1+2+3  (the sequence has one valid element)
(the sequence has three valid parts, with the first and second parts having version numbers)  
 
  
  iwl2030,lz4,mydatabase-13i.222.5b,e2fsprogs,PyYAML
+
  10,1+2+3,-20  (the sequence has three valid elements)
(the sequence has five valid parts, where only the third part has a version number)  
 
  
==== Examples of sequences the regular expression must NOT match: ====
+
-0,2*-3+7,-11,33/-11*-5,-12/6,19,77,1-2+3-4+5  (the sequence has eight valid elements)
  
coreutils, pcre-8.32
+
=== Examples of sequences the regular expression must NOT match: ===
(the second part begins with a space character which is illegal)
 
  
  coreutils 8.22,pcre--8.32
+
  22+11,   (there is a comma after the first sequence element, but the second element is missing)
(the first part contains a space character which is illegal; also, in the second part the software module name and version number are separated by two dash characters which is illegal)  
 
  
  m4-1.4.16,
+
  120+,3-4   (the first sequence element contains a plus character not followed by integer number)
(the first part ends with comma, but there is no following second part)  
 
  
  my_db
+
  -12-33,12+-1,5*6-3  (the second sequence element contains a plus character which is followed by a negative integer, but it is not allowed to use the minus character after plus)
(the software module name contains an illegal character _)  
 
  
  mydb-11A3.1
+
  1+2,,3+4  (the second sequence element is missing)
(the first version number element contains a character A, but A is not the last character of the version number element)  
 
  
  mydb-11..2
+
  11,12,+13  (the third sequence element starts with a plus character which is allowed only as a separator between two integer numbers)
(version number contains two dots, but there is no version number element between them)  
 
  
  mydb-
+
  12^3,2+3,55//11  (the first sequence element contains an illegal character ^; also the third element contains two consecutive slash characters, while only one is allowed)
(software module name is followed by -, but there is no version number)  
 
  
  mydb-12ab.1
+
  1+2+3,12*,2/3  (the second sequence element ends with an asterisk character which is allowed only as a separator between two integer numbers)
(the first version number element ends with more than one letter which is illegal)
 
  
  mydb,,mydaemon
+
  11,45+3, 100  (there is an illegal space character after the second separating comma)
(the second part of the sequence is empty)  
 
  
  !"libtasn1-4.09a,GeoIP-1.5.0,iwl6000g2a
+
  60 ,-4+0  (there is an illegal space character before the first separating comma)
  (the sequence begins with illegal characters)  
 
  
  coreutils-8.22,pcre-8.32+%
+
  --10A  (the sequence has one element which starts with two minus characters, while only one minus is allowed; also, the element ends with an illegal character A)
(the sequence ends with illegal characters)
 

Viimane redaktsioon: 21. september 2024, kell 13:57

This homework assignment requires the knowledge from Module 3.

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

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

2) Each element of the sequence is an expression that can consist of digits 0 1 2 3 4 5 6 7 8 9 and the plus (+), minus (-), asterisk (*), and slash (/) characters. No other characters (such as spaces or letters) are permitted in the element. The element must contain one or more integer numbers, where the integer number is defined as a non-empty sequence of digits. If the element has more than one integer number, two consecutive integer numbers must be separated with a single plus, minus, asterisk or slash character. If the asterisk or slash separates two integer numbers, an optional minus (-) character can appear before the second (right-hand side) integer number. However, if two integer numbers are separated by plus or minus character, the minus prefix is not allowed for the second integer. Also, an optional minus (-) character can appear before the first integer number in the element (in other words, the first character of the element can be either a minus or a digit).

For example, the following are valid sequence elements:

012
-1
2+3
-0+12-7
22+90*-2/60
-100+16/-2*-30

However, the following sequence elements are invalid:

1 + 2 (the space character appears both before and after the plus character, but the use of spaces is illegal)
1%2 (an illegal character % appears between two integer numbers)
12C (an illegal character C appears after the integer number)
12--2 (if the minus character separates two integer numbers, it is not allowed to use the minus prefix for the second integer)

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. 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:

1+2+3   (the sequence has one valid element)
10,1+2+3,-20   (the sequence has three valid elements)
-0,2*-3+7,-11,33/-11*-5,-12/6,19,77,1-2+3-4+5  (the sequence has eight valid elements)

Examples of sequences the regular expression must NOT match:

22+11,   (there is a comma after the first sequence element, but the second element is missing)
120+,3-4   (the first sequence element contains a plus character not followed by integer number)
-12-33,12+-1,5*6-3   (the second sequence element contains a plus character which is followed by a negative integer, but it is not allowed to use the minus character after plus)
1+2,,3+4   (the second sequence element is missing)
11,12,+13   (the third sequence element starts with a plus character which is allowed only as a separator between two integer numbers)
12^3,2+3,55//11   (the first sequence element contains an illegal character ^; also the third element contains two consecutive slash characters, while only one is allowed)
1+2+3,12*,2/3   (the second sequence element ends with an asterisk character which is allowed only as a separator between two integer numbers)
11,45+3, 100   (there is an illegal space character after the second separating comma)
60 ,-4+0  (there is an illegal space character before the first separating comma)
--10A   (the sequence has one element which starts with two minus characters, while only one minus is allowed; also, the element ends with an illegal character A)