Escaping special regex metacharacters and escaping rules inside the character classes

We know that . matches any character, [ and ] are used for character classes, { and } are used for limiting quantifiers, and ? , *, and + are used for various quantifiers. To match any of the metacharacters literally, one needs to escape these characters using a backslash ( ) to suppress their special meaning. Similarly, ^ and $ are anchors that are also considered regex metacharacters.

Let's see some examples of escaping metacharacters in regular expressions.

The following regex matches the string, a.b?:

     a.b? 

The following regex matches the string, {food}:

    {food} 

The following regex matches the string, abc:][}{:

    abc:][}{ 

The following regex matches the string, $25.50:

    $d+.d+

The following regex matches the string, ^*+.:

    ^*+. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.97.126