Regex by 131357
Click here to load reader
-
Upload
junaid-lodhi -
Category
Engineering
-
view
98 -
download
2
Transcript of Regex by 131357
![Page 1: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/1.jpg)
REGULAR EXPRESSIONS
Junaid LodhiRoll # 131357Air University Pakistan
![Page 2: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/2.jpg)
WHY TO STUDY REGULAR EXPRESSION?
Todays’s Agenda
![Page 3: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/3.jpg)
WHAT IS REGULAR EXPRESSION? regular expressions are used to generate patterns of strings. A regular expression is an algebraic formula whose value is a pattern consisting of a set of strings, called the language of the expression. This regular expression describes Canadian postal codes /^[A-Z][0-9][A-Z] [0-9][A-Z][0-9]$/
Any language accepted by the Finite Automata can be represented by Regular Expression
![Page 4: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/4.jpg)
OPERATORS USED IN REGULAR EXPRESSIONSI. Union: If R1 and R2 are regular expressions, then R1 | R2 (also
written as R1 U R2 or R1 + R2) is also a regular expression.L(R1|R2) = L(R1) U L(R2).
II. Concatenation: If R1 and R2 are regular expressions, then R1R2 (also written as R1.R2) is also a regular expression.L(R1R2) = L(R1) concatenated with L(R2).
III. Kleene closure: If R1 is a regular expression, then R1* (the Kleene closure of R1) is also a regular expression.L(R1*) = epsilon U L(R1) U L(R1R1) U L(R1R1R1) U ...
NOTE:Closure has the highest precedence, followed by concatenation, followed by union.
![Page 5: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/5.jpg)
EXAMPLES OF REGULAR EXPRESSION
The set of strings over {A..Z,a..z} that contain the word "main".Let <letter> = A | B | ... | Z | a | b | ... | z <letter>* main <letter>*
![Page 6: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/6.jpg)
EXAMPLES CONTINUED Set of EVEN Length String Regular expression can be made as
![Page 7: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/7.jpg)
EXAMPLES CONTINUED Set of ODD Length String Regular expression can be made as
![Page 8: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/8.jpg)
EXAMPLE CONTINUED Set of Strings Divisible by 3 Regular expression can be made as
![Page 9: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/9.jpg)
PRACTICE QUESTION Congruent to 2 mod 3 What can be the Regular Expression?
![Page 10: Regex by 131357](https://reader038.fdocuments.us/reader038/viewer/2022100513/58d149d81a28ab41128b4577/html5/thumbnails/10.jpg)