Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)

Similar presentations


Presentation on theme: "Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)"— Presentation transcript:

1 Lecture # 3 Regular Expressions 1

2 Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. It is basically one of the way to represent a set of language. 2

3 Introduction (cont..)  As we have discuss earlier Σ *  This notation is sometimes known as Kleene star  If Σ = {x}, then  Σ * = L 1 = {Λ x xx xxx xxxx……….}  If Σ = {0 1} then  Σ * = L 2 = {Λ 0 1 00 01 10 11 000 001…….}  If Σ = {a b c} then  Σ * = L 3 = {Λ a b c aa ab ac ba bb bc ca cb cc aaa …..} 3

4 Introduction(cont….)   is the set of all strings obtained by concatenating one or more symbols and having no Lambda means there must be at least one character.  ={y}   ={y, yy, yyy, yyyy,…}  ={0,1}   ={0,1,00,11,01,001……..} 4

5 Example Now consider the following Language L. L = {a,ab,abb,abbb,abbbb……} We could summarize this language by the english phrase “ All words of the language include one a followed by some number or combination of b’s” (maybe no b’s at all) So it regular expressions can be written as L = (a b * ) 5

6 Cont… The meaning is clear. This is a language in which the words are the concatenation an initial a with some or no b’s (i.e. b*) Whether we put space inside (ab*) or not (a b*) both give the same meanings. 6

7 Example Consider the language L = {aa, aba, abba,abbba, abbbba…….} it is the set of all strings of a’s and b’s that have atleast two letters. That begin and end with a’s and that have nothing but b’s inside. So we can express it as L= a b* a 7

8 Example Consider a language L = { Λ, a, b, aa, bb, aabb, aaa, bbb ……} It contains all the strings of a’s and b’s in which all the a’s (if any ) comes before all the b’s(if any) So we can express it as L = a* b* 8

9 Example Now consider the following Language L. L = {ab,abb,abbb,abbbb……} We could summarize this language by the english phrase “ All words of the language include one a followed by some number or combination of b’s” So it regular expressions can be written as L = (a b + ) 9

10 Example 10 Consider a language L = { acb, accbb, acccbbb, accccbbbb……….} The language can be defined as each word is starting with a and having equal combination of b and c but atleast one c and one b. L = a b + c +

11 Example 11 Define a regular expression for a language having even no of x L = { Λ, xx, xxxx, xxxxxx, xxxxxxxx…….} the above language contain the add number of x’s in the set. L = (xx)*

12 Example 12 Define a regular expression for a language having odd no of x L = {x, xxx, xxxxx, xxxxxxx…….} the above language contain the add number of x’s in the set. L = x (xx)*

13 Example 13 Consider a language L = { Λ, a, c, aa, cc, aaa, ccc, aaaa, cccc…….} We can define it as it is either the combination a ‘s or c’s, so we can write the regular expression as L = (a + c) * We (a + c) represent that either a or c, not both a same point.

14 Example 14 Consider the following Language L = {a, c, ab, cb, abb, cbb, abbb, cbbb…….} All the words in above language start with either a or c followed by some combination of b, so we can write the regular expression as L = (a + c)b*

15 Examples 15 Consider the following language L = {a, ab, ac, abb, acc, abbb, accc ….} The language L show that every word of this set start with a and is followed by either combination of b or c. So; L = a ( b + c)*

16 Example 16 Given the Set Σ = {a,b} The language is the set of all words over the above set that have atleast one a. What would be the regular expression for the above condition. L = a (a+b)*

17 Example 17 Consider the set Σ = {a, b} The language is the set of all words over the above set that starts and ends at a. What would be the regular expression for the above condition. L = a (a+b)* b

18 Example 18 Consider the set Σ = {a, b, c} The language is the set of all words over the above set that starts with a and ends at c. What would be the regular expression for the above condition. L = a (a+b+c)* c

19 End of Chapter 19


Download ppt "Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)"

Similar presentations


Ads by Google