Erinevus lehekülje "Itx8071-task1" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
26. rida: 26. rida:
 
==== Examples of sequences the regular expression must match: ====
 
==== Examples of sequences the regular expression must match: ====
  
1+2+3  (the sequence has one valid element)
+
'''1+2+3'''   (the sequence has one valid element)
  
10,1+2+3,-20  (the sequence has three valid elements)
+
'''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)
+
'''-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: ====
 
==== 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)
+
'''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)
+
'''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 integer, but the integer starts with a minus sign that is only allowed after * or /)
+
'''-12-33,12+-1,5*6-3'''   (the second sequence element contains a plus character which is followed by integer, but the integer starts with a minus sign that is only allowed after * or /)
  
1+2,,3+4  (the second sequence element is missing)
+
'''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)
+
'''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 illegal character ^; also the third element contains two consecutive slash characters, while only one is allowed)
 
12^3,2+3,55//11  (the first sequence element contains 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)
+
'''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)
+
'''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)
+
'''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)
+
'''--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)

Redaktsioon: 29. september 2016, kell 09:23

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, letters, etc.) are permitted in the element. The element must contain one or more integer numbers (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. 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 elements:

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.

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 integer, but the integer starts with a minus sign that is only allowed after * or /)

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 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)