0% found this document useful (0 votes)
39 views2 pages

Exercise 2.1 - Regular Expressions

This document contains regular expressions that match various string patterns: 1) Regular expressions for strings of lowercase letters beginning and ending in 'a', strings beginning or ending in a letter, and strings of digits containing no leading zeros. 2) Regular expressions for even number strings, strings where all 2s come before 9s, strings of a's and b's with no three consecutive b's, and strings with an odd number of a's and b's. 3) Regular expressions for strings with an even number of a's and b's, and a note that exactly matching numbers of a's and b's is impossible without counting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Exercise 2.1 - Regular Expressions

This document contains regular expressions that match various string patterns: 1) Regular expressions for strings of lowercase letters beginning and ending in 'a', strings beginning or ending in a letter, and strings of digits containing no leading zeros. 2) Regular expressions for even number strings, strings where all 2s come before 9s, strings of a's and b's with no three consecutive b's, and strings with an odd number of a's and b's. 3) Regular expressions for strings with an even number of a's and b's, and a note that exactly matching numbers of a's and b's is impossible without counting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise 2.

1 – regular expressions
a) All strings of lowercase letters that begin and end in a
a([a-z]*a)?
b) All strings of lowercase letters that either begin or end in a (or both)
a[a-z]* | [a-z]*a
c) All strings of digits that contain no leading zeroes

INF 3110/4110 - 2004


nonzero = 1 | 2 | … | 9
digit = 0 | nonzero
answer = 0 | nonzero digit*
d) All strings of digits that represent even numbers
even = 0 | 2 | 4 | 6 | 8
answer = even | [1-9] [0-9]* even
e) All strings of digits such that all the 2’s occur before all the 9’s
dignot9 = 0 | 1 | … | 8
dignot2 = 0 | 1 | 3 | 4 | … | 9

INF 5110
answer = dignot9* dignot2*
f) All strings of a’s and b’s that contain no three consecutive b’s
(a | ba | bba)* (e | b | bb)
22.01.2013 1
Exercise 2.1 – regular expressions
g) All strings of a’s and b’s that contain an odd number of a’s and an odd
number of b’s (or both)
b*ab*(ab*ab*)* | a*ba*(ba*ba*)*
h) All strings of a’s and b’s that contain an even number of a’s and an even
number of b’s
(aa | bb)* ( (ab | ba) (aa | bb)* (ab | ba) (aa | bb)* )*

INF 3110/4110 - 2004


INF 5110
i) All strings that contain exectly as many a’s and b’s
impossible – requires counting of arbitrary many a’s

22.01.2013 2

You might also like