Adobe Scan 18 Nov 2022
Adobe Scan 18 Nov 2022
10 Applications of RE
MU Dec. 2012, May 2014, May 2015, Dec. 2017
3.10.1 R.E. in Unix
The UNX regular expression lets us specify a group of characters using a pair of square
brackets [ 1. The rules for character classes are
1. [ab] Stand for a + b
2. [0-9 Stand for a digit from 0 to 9
3 [A-Z Stands for an upper-case letter
4. [a-z] Stands for a lower-case letter
5.
[0-9A-Za-z1 Stands for a letter or a digit.
The grep utility in UNIX, scans a file for the occurrence of a pattern and displays those
lines in which the given pattern is found.
For example:
grep president emp.txt
3-74 Regular Expressions
Theory of Comp. Sci. (MU-Sem. 5-Comp.) and Lano
file emp.txt which has the pattern
It will list those lines from the
pattern in grep command can be specified using
regular expression. dent'. Te
6. matches zero or more
occurrences of previous character.
7. matches a single character.
is not a p, q orr.
8. pqrl Matches a single character which
Matches pattern pat at the beginning of a line
9. pat
10. pat $ Matches pattern at end of line.
Example
(a) The regular expression [aA] g [ar] [ar] wal stands for either "Agarwal" or'aren
(b) gstands for zero or more occurrences of g.
Sgrep "A * thakur" emp.txt will look for a pattern starting with A. and endingwi
(C)
thakur in the file emp.txt.
An identifier
Assignment operator
Y An identifier
Arithmetic operator+
Z An identifier
Keywords, identifiers and operators are common examples of tokens.
The UNIX to l
utility lex can be used for writing of a lexical analysis program. p
for
is a set of
regular expressions for each type of token and output of lex is a Cprog
lexical analysis.