0% found this document useful (0 votes)
5 views2 pages

Regular PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Regular PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Define Regular Explain and Explain Different types of Regular Expression?

A regular expression is a pattern consisting of a sequence of characters i.e. matched


against text. A regular expression is like a mathematical expression. A mathematical expression is
made of operands (data) and operators. Similarly, a regular expression is made of atoms and
operators.

Regular Expression there are two types

Atoms Operators

1. Atoms:

 An atom specifies what text is to be matched and where it is to be found.


 An operator combines regular expression atoms.


 Single Character: The simplest atom is a single character. When a single character appears in a
regular expression, it matches itself. In other words, if a regular expression is made of one single
character, that character must be somewhere in the text to make the pattern match successful.
 Example:$grep “HELLO” filename

 Dot: A dot matches any single character except the new line character(\n).This universal
matching capability makes it a very powerful element in the operation of regular
expressions.
 Example:

 Class: The class atom defines a set of ASCII characters, any one of which may match any
of the characters in the text.
The character set to be used in the
matching process is enclosed in
brackets.
Example: [ABC] matches either A, B, or C.

 Anchors tell where the next character in the pattern must


be located in the text data.
 Back references: We can temporarily save text in one of the nine save buffers. When we do we refer the text
in a saved buffer using a back reference. A back reference is coded using the escape character rand a digit in
the range of [1-9] as shown below:

\1 \2 .. . \9

2. OPERATORS:

 To make the regular expressions more powerful, we can combine atoms with operators. The
regular expression operators play the same role as mathematical operators. Mathematical
expression operators combine mathematical atoms (data); regular expression operators combine
regular expression atoms.
 We can group the regular expressions into five different categories: sequence operators,
alternation operators, repetition operators, group operators, and save operators.
 Sequence operators: The sequence operator is nothing. this means that if a series of atoms ,such
as a series of characters
 Alternation operators: The alternation operators( | ) is used to define one or more alternatives.
For example, if we want to select between A or B, we would code the regular expression as A|B.
EXAMPLE: UNIX| Unix =>matches “UNIX” or “unix”
 repetition operators: The repetition operator is a set of escaped braces (\ {… \}).
Example: A \{3 …5 \} =>matches “AAAA, or “AAAAA”
 group operators: In the group operator, when a group of characters is enclosed in parentheses, the
next operator applies to the
 whole group, not only the previous characters
 Example:

 Note: depends on version of “grep”

use \( and \) instead

You might also like