Header Ads

  • Highlights

    👩🏻‍💻 Hello Readers 🧑🏻‍💻!!! Would you like to Explore more ? Hit on ⓘ(Ads)... ✨🌹

    What is Regular Expression in TOC ?


    Regular Expression (RE, regex, regexp) is : 

    An expression that expresses the set of strings according to certain syntax rules is considered a regular expression. These expressions have certain notations which we can describe in the regular language. This notation involves a combination of strings of symbols from some alphabet Σ, parentheses, and the operators +, ·, and .

    In terms of the theory of computation the regular can be defined as a language or string accepted by a Finite Automata. We know that a finite automaton consists of 5 tuples {Q, Σ, δ, q0, F}. A regular expression is a string on Σ, i.e., it consists of only input alphabets.

    Let Σ be an alphabet. The regular expression over Σ and the sets they denote are:

    • Ф is an r.e and denotes an empty set
    • є is an r.e and denotes the set { є }
    • For each ‘a’ in Σ, a+ is an r.e and denotes the set {a}

     If ‘r’ and ‘s’ are r.e. denoting the languages R and S respectively the (r+s), (r.s) and (r*)     are r.e that denote the sets RUS, R.S and R* respectively

    Basic Operations on Regular Expression

    Three basic operations are union, concatenation, and closure.

    ·        The operation of the union on RE: 

            If R1 and R2 are two REs over Σ, then L(R1  R2) is denoted by L(R1 + R2).

    L(R1  R2) is a string from R1 or a string from R2.

    L(R1 + R2) = L(R1)  L(R2).

    ·        The operation of concatenation on RE: 

            If R1 and R2 are two REs over Σ, then L(R1 ∩ R2) is denoted by L(R1R2).

    L(R1 ∩ R2) is a string from R1 followed by a string from R2.

    L(R1.R2) = L(R1).L(R2)

    ·      The operation of closure on RE: 

    If R1 and R2 are two REs over Σ, then L(R*) is a string obtained by concatenating n elements for n ≥ 0.

    Kleene’s Closure

    It is defined as a set of all strings including null (Λ) obtained from the alphabets of the set Σ. It is denoted as Σ*.

    ·            If Σ = {0}, then Σ* = {Λ, 0, 00, 000…}

                  ·            If Σ = {0, 1}, then Σ* = {Λ, 0, 1, 01, 00, 11, 010, 011, 100…}     

    Do you know What is the Difference between Closure and Kleene’s Closure?

    Consider the following examples for a better understanding of Regular Expression

    Regular Expression

    Possible String generated

    In English, it is described as:

    10*1

    11, 101, 1001, 1001…..}

    Set of all strings beginning and ending with 1 with any number of 0 in between the two 1s.

    a*b*

    {Λ, a, b, aa, bb, ab, abb, aab,...}

    Set of all strings of ‘a’ and ‘b’ containing any number of ‘a’ followed by any number of ‘b’.

    (ab)*

    {Λ, ab, abab, ababab, …}

    Set of all strings of a and b with an equal number of a and b containing ‘ab’ as repetition

    (a* + b*) c*

    a, aa, aaa, aaa.., b, bb, bbb, bbb..,c, cc, cc…, ac, aac, acc, b, ,bbc, bcc…

    Any combination of ‘a’ or any combination of ‘b’ followed by any combination of ‘c’

    (00)*(11)*1

    {1, 001, 111, 00111, ……}

    Set of all strings of ‘0’ and ‘1’ with even number of 0 followed by an odd number of 1.

     Also, Study about: 

    Also Read, some interview tips

    No comments

    Post Bottom Ad

    Powered by Blogger.