## Regular expression examples

### Regular Expression Examples:

Example 1: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that,

w contains only a's or only b's of length zero or more.

Solution:  r = a* + b*

Example 2: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w is of length one or more and contains only a's or only b's. r = a+ + b+

Solution:  r = a+b+

Example 3: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w contains zero or more a's followed by zero or more b's

Solution: r = a*b*

Example 4: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w of length even

Solution: r = [(a + b) (a + b)]*

Example 5: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w of length odd

Solution: r = (a + b) [(a + b) (a + b)]*

Example 6: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w of length three

Solution: r = (a + b) (a + b) (a + b)

Example 7: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w of length atmost three

Solution:  r = (a + b + ∈) (a + b + ∈) (a + b + ∈)

Example 8: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w of length odd containing only b's

Solution: r = (bb)* b

Example 9: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w starting with a always

Solution: r = a(a + b)*

Example 10: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w starting and ending with b and having only a's in between.

Solution:  r = b a* b

Example 11: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w starting and ending with same double letter

Solution: r = {(aa (a + b)* aa) | (bb (a + b)* bb)

Example 12: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with starting and ending with different letters

Solution: r = (a(a+b)* b) | (b (a + b)* a)

Example 13: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with at least two occurrence of a

Solution: r = (a + b)* a (a + b)* a (a + b)*

Example 14: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with exactly two occurrence of a

Solution:  r = b* a b* a b*

Example 15: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with at most two occurrence of a

Solution: r = b* (a + ∈) b* (a + ∈) b*

Example 16: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with begin or end with aa or bb

Solution: r = ((aa + bb) (a + b)*) + ((a + b) * (aa + bb))

Example 17: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with begin and end with aa or bb

Solution: r = ((aa + bb) (a + b)* (aa + bb)) + aa + bb

Example 18: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with total length multiple of 3 always

Solution: r = [(a + b) (a + b) (a + b)]*

Example 19: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w containing total a's as multiple of 3 always

Solution: r = [b* a b* a b* a b*]*

Example 20: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with exactly two or three b's

Solution: r = a* b a* b a* (b + ∈) a*

Example 21: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with number of a's even

Solution: r = b* + (b* a b* a b*)*

Example 22: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w in which b is always tripled

Solution: r = (a + bbb)*

Example 23: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with at least one occurrence of substring aa or bb

Solution:  r = (a + b)* (aa + bb) (a + b)*

Example 24: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w with at the most one occurrence of sub-string bb

Solution: r = (a + ba)* (bb + ∈) (a + ab)*

Example 25: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w without sub-string ab

Solution: r = b* a*

Example 26: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w without sub-string aba

Solution: r = (a + ∈) (b + aa+ )* (a + ∈)

Example 27: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w in which 3rd character from right end is always a

Solution: r = (a + b)* a (a + b) (a + b)

Example 28: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w always start with 'a' and the strings in which each 'b' is preceded by 'a'.

Solution: (a + ab)*

Example 29: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w contains atleast one 'a'.

Solution: (a + b)* a (a + b)*

Example 30: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w contain atleast two 'a's or any number of 'b's.

Solution: (a* a b* a b*) + b*

Example 31: Let Σ = {a, b}. Write regular expression to define language consisting of strings w such that, w contain atleast one 'a' followed by any number of 'b's followed by atleast one 'c'.

Solution: a+ b* c+

Recommended:

ACA: ADVANCED COMPUTER ARCHITECTURE EasyExamNotes.com covered following topics in these notes.
Discrete Strucutre ↓ 👆
Discrete Structure EasyExamNotes.com covered following topics in these notes.
A list of Video lectures
Information Storage Management ↓ 👆
Network & Web Security ↓ 👆
Web Engineering ↓ 👆
Web Engineering EasyExamNotes.com covered following topics in these notes.
Cloud Computing ↓ 👆

Cloud Computing:

EasyExamNotes.com covered following topics in Cloud Computing.

1. Buyya, Selvi ,” Mastering Cloud Computing “,TMH Pub
2. Krutz , Vines, “Cloud Security “ , Wiley Pub
3. Velte, “Cloud Computing- A Practical Approach” ,TMH Pub
4. Sosinsky, “ Cloud Computing” , Wiley Pub
Python Programming ↓ 👆
Principles of Programming Languages ↓ 👆
Principles of Programming Languages
EasyExamNotes.com covered following topics in these notes.

#### Language Evaluation Criteria Influences on Language Design  Language Categories Programming Paradigms Compilation Virtual Machines  Programming Environments Issues in Language Translation Parse Tree  Pointer and Reference type Concept of Binding Type Checking Strong typing  Sequence control with Expression Subprograms Fundamentals of sub-programs Scope and lifetime of variable Static and dynamic scope Design issues of subprogram and operations Local referencing environments Parameter passing methods Overloaded sub-programs Generic sub-programs  Design issues for functions  Co routines  Abstract Data types Abstraction and encapsulation Static and Stack-Based Storage management Garbage Collection OOP in C++ OOP in Java  OOP in C#  OOP in PHP Concurrency Semaphores  Monitors Message passing Java threads  C# threads  Exception handling  Exceptions Exception Propagation  Exception handler in C++  Exception handler in Java Introduction and overview of Logic programming Basic elements of Prolog Application of Logic programming Functional programming languages Introduction to 4GL  Practicals: Memory Implementation of 2D Array.  Memory Implementation of 3D Array.  Implementation of pointers in C++.  Write a program in Java to implement exception handling. Write a program in C++ to implement call by value parameter passing Method. Write a program in C++ to implement call by reference parameter passing Method.  Write a program in Java to implement concurrent execution of a job using threads. Implement Inheritance in C#. Implement Encapsulation in C#. Implement static/compiletime Polymorphism in C#. Implement dynamic/runtime Polymorphism in C#. Previous years solved papers: PPL|RGPV|May 2018  PPL|RGPV|June 2017  A list of Video lectures Click here References: Sebesta,”Concept of programming Language”, Pearson Edu  Louden, “Programming Languages: Principles & Practices” , Cengage Learning  Tucker, “Programming Languages: Principles and paradigms “, Tata McGraw –Hill.  E Horowitz, "Programming Languages", 2nd Edition, Addison Wesley

Computer Organization and Architecture ↓ 👆

### Computer Organization and Architecture

#### References:

1. William stalling ,“Computer Architecture and Organization” PHI
2. Morris Mano , “Computer System Organization ”PHI

Theory of Computation ↓ 👆
TOC EasyExamNotes.com covered following topics in these notes.
Computer Network ↓ 👆
Computer Network

EasyExamNotes.com covered following topics in these notes.
References:
1. Andrew S. Tanenbaum, David J. Wetherall, “Computer Networks” Pearson Education.
2. Douglas E Comer, “Internetworking with TCP/IP Principles, Protocols, And Architecture",Pearson Education
3. KavehPahlavan, Prashant Krishnamurthy, “Networking Fundamentals”, Wiley Publication.
4. Ying-Dar Lin, Ren-Hung Hwang, Fred Baker, “Computer Networks: An Open Source Approach”, McGraw Hill.
R Programming ↓ 👆

### R Programming

EasyExamNotes.com covered following topics in these notes.

Management Information System ↓ 👆