Itx8071-task1

Allikas: Kursused
Redaktsioon seisuga 25. september 2026, kell 12:06 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 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, letters X Y Z, and the plus (+), minus (-), asterisk (*), slash (/), and circumflex (^) characters. No other characters (such as spaces or letters) are permitted in the element. The element must contain one or more operands, where operand is either an integer number or a variable. The integer number is defined as a non-empty sequence of digits. The variable is defined as a single letter X, Y, or Z.

3) If the operand is a variable, the operand may have the following suffix -- a single circumflex (^) character, followed by an optional minus (-) character, followed by at least one digit. If the operand is an integer number, this suffix is not permitted.

4) If the element has more than one operand, two consecutive operands must be separated with a single plus, minus, asterisk or slash character. If the asterisk or slash separates two operands, an optional minus (-) character can appear before the second (right-hand side) operand. However, if two operands are separated by plus or minus character, the minus prefix is not allowed for the second operand. Also, an optional minus (-) character can appear before the first operand in the element (in other words, the first character of the element can be either a minus, a digit, or a letter X, Y, or Z).