Professional Documents
Culture Documents
Theory of Autamata 3
Theory of Autamata 3
Theory of Autamata
Computer Science
I declare that this assessment item is my own work unless otherwise acknowledged and is
in accordance with the University’s academic integrity policy.
I certify that this assessment item has not been submitted previously for academic credit in
this or any other course. I certify that I have not given a copy or have shown a copy of this
assessment item to another student enrolled in the course.
I acknowledge that the assessor of this assignment may, for the purpose of assessing this
assignment:
Reproduce this assessment item and provide a copy to another member of the Faculty; and/or
Communicate a copy of this assessment item to a plagiarism checking service (which may then
retain a copy of the item on its database for the purpose of future plagiarism checking).
Submit the assessment item to other forms of plagiarism checking.
I certify that any electronic version of this assessment item that I have submitted or will
submit is identical to this paper version.
The process of analyzing or modifying a text with a regex is called: The regular expression is
applied to the text/string. The pattern defined by the regex is applied on the text from left to
right. Once a source character has been used in a match, it cannot be reused. For example, the
regex aba will match ababababa only two times (aba_aba__).
The concept arose in the 1950s when the American mathematician Stephen Cole
Kleene formalized the description of a regular language. The concept came into common use
with Unix text-processing utilities. Different syntaxes for writing regular expressions have
existed since the 1980s, one being the POSIX standard and another, widely used, being
the Perl syntax.
Regular expressions are used in search engines, search and replace dialogs of word
processors and text editors, in text processing utilities such as sed and AWK and in lexical
analysis. Many programming languages provide regex capabilities either built-in or via libraries.
Example
Write the regular expression for the language accepting all the string which are starting with 1
and ending with 0, over ∑ = {0, 1}.
Solution:
In a regular expression, the first symbol should be 1, and the last symbol should be 0. The r.e. is
as follows:
R = 1 (0+1)* 0
Example
Write the regular expression for the language starting and ending with a and having any having
any combination of b's in between.
Solution:
Example
Write the regular expression for the language starting with a but not having consecutive b's.
L = {a, aba, aab, aba, aaa, abab, .....}
R = {a + ab}*
Example
Write the regular expression for the language accepting all the string in which any number of a's
is followed by any number of b's is followed by any number of c's.
Solution: As we know, any number of a's means a* any number of b's means b*, any number of
c's means c*. Since as given in problem statement, b's appear after a's and c's appear after b's. So
the regular expression could be:
R = a* b* c*
Example
Write the regular expression for the language over ∑ = {0} having even length of the string.
Solution:
L = {ε, 00, 0000, 000000, ......}
R = (00)*
Example
Write the regular expression for the language having a string which should have atleast one 0 and
alteast one 1.
Solution:
R = [(0 + 1)* 0 (0 + 1)* 1 (0 + 1)*] + [(0 + 1)* 1 (0 + 1)* 0 (0 + 1)*]
Example
r.e. = (b* (aaa)* b*)*
Solution:
The language can be predicted from the regular expression by finding the meaning of it. We will
first split the regular expression as:
L = {The language consists of the string in which a's appear triples, there is no restriction on the
number of b's}
Example
Write the regular expression for the language L over ∑ = {0, 1} such that all the string do not
contain the substring 01.
Solution:
L = {ε, 0, 1, 00, 11, 10, 100, .....}
R = (1* 0*)
Example
Write the regular expression for the language containing the string over {0, 1} in which there are
at least two occurrences of 1's between any two occurrences of 1's between any two occurrences
of 0's.
Solution: At least two 1's between two occurrences of 0's can be denoted by (0111*0)*.
Similarly, if there is no occurrence of 0's, then any number of 1's are also allowed. Hence the r.e.
for required language is:
R = (1 + (0111*0))*
Example
Write the regular expression for the language containing the string in which every 0 is
immediately followed by 11.
Solution:
R = (011 + 1)*
Meta-
characte Description Example[51]
r(s)
Output:
Hello World
has length >=
5.
$string1 =
"Hello
World\n";
if ($string1
=~ m/(H..).
(o..)/) {
print "We
Groups a series of pattern elements to a single element.
matched '$1'
( ) When you match a pattern within parentheses, you can use any and '$2'.\n";
of $1 , $2 , ... later to refer to the previously matched pattern. }
Output:
We matched
'Hel' and 'o
W'.
$string1 =
"Hello
World\n";
if ($string1
=~ m/l+/) {
print "There
are one or
more
consecutive
letter \"l\"'s
in
+ Matches the preceding pattern element one or more times. $string1.\n";
}
Output:
Output:
There is an
'H' and a 'e'
separated by
0-1 characters
(e.g., He Hue
Hee).
Output:
The non-greedy
match with 'l'
followed by
one or more
characters is
'llo' rather
than 'llo Wo'.
$string1 =
"Hello
World\n";
if ($string1
=~ m/el*o/) {
print "There
is an 'e'
followed by
zero to many
";
print "'l'
followed by
'o' (e.g., eo,
* Matches the preceding pattern element zero or more times. elo, ello,
elllo).\n";
}
Output:
There is an
'e' followed
by zero to
many 'l'
followed by
'o' (e.g., eo,
elo, ello,
elllo).
Output:
There exists a
substring with
at least 1 and
at most 2 l's
in Hello World
$string1 =
"Hello
World\n";
if ($string1
=~ m/[aeiou]
+/) {
print
"$string1
contains one
[…] Denotes a set of possible character matches. or more
vowels.\n";
}
Output:
Hello World
contains one
or more
vowels.
$string1 =
"Hello
World\n";
if ($string1
=~ m/(Hello|
Hi|Pogo)/) {
print
"$string1
contains at
least one of
| Separates alternate possibilities. Hello, Hi, or
Pogo.";
}
Output:
Hello World
contains at
least one of
Hello, Hi, or
Pogo.
$string1 =
"Hello
World\n";
if ($string1
=~ m/llo\b/) {
print "There
Matches a zero-width boundary between a word-class character is a word that
(see next) and either a non-word class character or an edge; same ends with
\b as 'llo'.\n";
}
(^\w|\w$|\W\w|\w\W) .
Output:
There is a
word that ends
with 'llo'.
Output:
Hello
World
is a
line or
string
that
ends
with
'rld'.