0% found this document useful (0 votes)
11 views3 pages

Regular Expressions Excercises

This document contains regular expressions to match various strings: 1) Strings of lowercase letters that begin and end in the same letter, or begin or end in any letter. 2) Strings of digits that do not contain leading zeros or that represent even numbers. 3) Strings where all 2s occur before all 9s or strings of a's and b's without three consecutive b's. 4) Strings of a's and b's with an odd number of each letter or an even number of each letter.

Uploaded by

Zeyad Elmoghazy
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)
11 views3 pages

Regular Expressions Excercises

This document contains regular expressions to match various strings: 1) Strings of lowercase letters that begin and end in the same letter, or begin or end in any letter. 2) Strings of digits that do not contain leading zeros or that represent even numbers. 3) Strings where all 2s occur before all 9s or strings of a's and b's without three consecutive b's. 4) Strings of a's and b's with an odd number of each letter or an even number of each letter.

Uploaded by

Zeyad Elmoghazy
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/ 3

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

a[a-z]* | [a-z]*a

INF 3110/4110 - 2004


c) All strings of digits that contain no leading zeroes

nonzero = 1 | 2 | ... | 9
digit = 0 | nonzero
answer = 0 | nonzero digit*

INF 5110
27/01/15 1
Exercise 2.1 regular expressions

d) All strings of digits that represent even numbers


even = 0 | 2 | 4 | 6 | 8
answer = even | [1-9] [0-9]* even

INF 3110/4110 - 2004


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
answer = dignot9+ dignot2+

f) All strings of a’s and b’s that contain no three consecutive b’s

(a | ba | bba)* (ε | b | bb)

INF 5110
27/01/15 2
g) All strings of a’s and b’s that contain an odd number of a’s and an odd number of
b’s
b*ab*(ab*ab*)* | a*ba*(ba*ba*)*

h) All strings of a’s and b’s with an even number of a’s and an even number of

INF 3110/4110 - 2004


b’s

(aa | bb)* ( (ab | ba) (aa | bb)* (ab | ba) (aa | bb)* )*

INF 5110
27/01/15 3

You might also like