PPT: Regular Expressions | Theory of Computation - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


1
Regular Expressions
Page 2


1
Regular Expressions
2
Regular Expressions vs. Finite
Automata
n Offers a declarative way to express the pattern of any
string we want to accept
n E.g., 01*+ 10*
n Automata => more machine-like
< input: string  , output: [accept/reject]  >
n Regular expressions => more program syntax-like
n Unix environments heavily use regular expressions
n E.g., bash shell, grep, vi & other editors, sed
n Perl scripting – good for string processing
n Lexical analyzers such as Lex or Flex
Page 3


1
Regular Expressions
2
Regular Expressions vs. Finite
Automata
n Offers a declarative way to express the pattern of any
string we want to accept
n E.g., 01*+ 10*
n Automata => more machine-like
< input: string  , output: [accept/reject]  >
n Regular expressions => more program syntax-like
n Unix environments heavily use regular expressions
n E.g., bash shell, grep, vi & other editors, sed
n Perl scripting – good for string processing
n Lexical analyzers such as Lex or Flex
3
Regular Expressions
Regular
expressions
Finite Automata
(DFA, NFA, e-NFA)
Regular
Languages
=
Automata/machines
Syntactical
expressions
Formal language
classes
Page 4


1
Regular Expressions
2
Regular Expressions vs. Finite
Automata
n Offers a declarative way to express the pattern of any
string we want to accept
n E.g., 01*+ 10*
n Automata => more machine-like
< input: string  , output: [accept/reject]  >
n Regular expressions => more program syntax-like
n Unix environments heavily use regular expressions
n E.g., bash shell, grep, vi & other editors, sed
n Perl scripting – good for string processing
n Lexical analyzers such as Lex or Flex
3
Regular Expressions
Regular
expressions
Finite Automata
(DFA, NFA, e-NFA)
Regular
Languages
=
Automata/machines
Syntactical
expressions
Formal language
classes
4
Language Operators
n Union of two languages:
n L U M = all strings that are either in L or M
n Note: A union of two languages produces a third
language
n Concatenation of two languages:
n L . M = all strings that are of the form xy
s.t., x Î L and y Î M
n The dot operator is usually omitted
n i.e., LM is same as L.M
Page 5


1
Regular Expressions
2
Regular Expressions vs. Finite
Automata
n Offers a declarative way to express the pattern of any
string we want to accept
n E.g., 01*+ 10*
n Automata => more machine-like
< input: string  , output: [accept/reject]  >
n Regular expressions => more program syntax-like
n Unix environments heavily use regular expressions
n E.g., bash shell, grep, vi & other editors, sed
n Perl scripting – good for string processing
n Lexical analyzers such as Lex or Flex
3
Regular Expressions
Regular
expressions
Finite Automata
(DFA, NFA, e-NFA)
Regular
Languages
=
Automata/machines
Syntactical
expressions
Formal language
classes
4
Language Operators
n Union of two languages:
n L U M = all strings that are either in L or M
n Note: A union of two languages produces a third
language
n Concatenation of two languages:
n L . M = all strings that are of the form xy
s.t., x Î L and y Î M
n The dot operator is usually omitted
n i.e., LM is same as L.M
5
Kleene Closure (the * operator)
n Kleene Closure of a given language L:
n L
0
= {e}
n L
1
= {w | for some w Î L}
n L
2
= { w
1
w
2
| w
1
Î L, w
2
Î L (duplicates allowed)}
n L
i
= { w
1
w
2
…w
i
| all w’s chosen are Î L (duplicates allowed)}
n (Note: the choice of each w
i
is independent)
n L* = U
i=0
L
i
(arbitrary number of concatenations)
Example:
n Let L = { 1, 00}
n L
0
= {e}
n L
1
= {1,00}
n L
2
= {11,100,001,0000}
n L
3
= {111,1100,1001,10000,000000,00001,00100,0011}
n L* = L
0
U L
1
U L
2
U …
“i” here refers to how many strings to concatenate from the parent
language L to produce strings in the language L
i
Read More
18 videos|69 docs|44 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on PPT: Regular Expressions - Theory of Computation - Computer Science Engineering (CSE)

1. What is a regular expression?
Ans. A regular expression, also known as regex, is a sequence of characters that forms a search pattern. It is used to match and manipulate text by specifying a set of rules for finding certain patterns within a string.
2. How are regular expressions useful in computer science engineering?
Ans. Regular expressions are widely used in computer science engineering for tasks such as text processing, pattern matching, data validation, and lexical analysis. They provide a powerful and flexible way to search, analyze, and manipulate text data efficiently.
3. What are some commonly used metacharacters in regular expressions?
Ans. Regular expressions use metacharacters to represent sets of characters or patterns. Some commonly used metacharacters include: - Dot (.) matches any single character. - Asterisk (*) matches zero or more occurrences of the previous character or group. - Plus sign (+) matches one or more occurrences of the previous character or group. - Question mark (?) matches zero or one occurrence of the previous character or group. - Pipe (|) represents an alternative choice between two patterns.
4. How can regular expressions be used for data validation?
Ans. Regular expressions can be employed to validate input data by defining specific patterns that the data must adhere to. For example, a regular expression can be used to ensure that an email address is in the correct format or that a phone number follows a specific pattern. By matching the input against the defined pattern, regular expressions can effectively validate the data.
5. Can regular expressions handle complex text manipulation tasks?
Ans. Yes, regular expressions are capable of handling complex text manipulation tasks. They can be used for tasks like searching and replacing specific patterns, extracting specific information from a text, and even performing advanced text transformations. Regular expressions provide a flexible and powerful toolset for text manipulation in computer science engineering.
18 videos|69 docs|44 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Important questions

,

Free

,

video lectures

,

Exam

,

past year papers

,

ppt

,

mock tests for examination

,

PPT: Regular Expressions | Theory of Computation - Computer Science Engineering (CSE)

,

practice quizzes

,

PPT: Regular Expressions | Theory of Computation - Computer Science Engineering (CSE)

,

Extra Questions

,

pdf

,

Semester Notes

,

shortcuts and tricks

,

PPT: Regular Expressions | Theory of Computation - Computer Science Engineering (CSE)

,

Summary

,

Viva Questions

,

study material

,

MCQs

,

Sample Paper

,

Objective type Questions

,

Previous Year Questions with Solutions

;