{"id":1804,"date":"2022-03-02T17:06:15","date_gmt":"2022-03-02T11:36:15","guid":{"rendered":"https:\/\/smarttech101.com\/?p=1804"},"modified":"2022-03-04T06:50:20","modified_gmt":"2022-03-04T01:20:20","slug":"regular-expression-regex-and-regexp-in-linux-ft-grep","status":"publish","type":"post","link":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/","title":{"rendered":"Regular Expression (Regex, and Regexp) in Linux Ft. Grep"},"content":{"rendered":"\n<p>A regular expression (also known as regex, and regexp) is a sequence of characters used by various programming languages such as python, Linux tools such as grep, awk, sed, etc. to match one or more strings. <\/p>\n\n\n\n<p>For instance, the regex &#8220;<code>R.*x<\/code>&#8221; matches with strings &#8220;<code>Regex<\/code>&#8220;, and &#8220;<code>Regular Expression in Linux<\/code>&#8220;, etc.<\/p>\n\n\n\n<p>Despite being super useful, there is not a single standard that is followed everywhere. For example, we have GNU Regex, POSIX Regex, Perl Regex, etc.<\/p>\n\n\n\n<p>However, there are very few variations across these standards. For instance, <code>sed<\/code> in Linux and Mac OS follow standards slightly different from each other. Here, in this article, I will be focusing mainly on the <strong>GNU Regex<\/strong> using<a href=\"https:\/\/smarttech101.com\/grep-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\"> grep command in Linux<\/a>. At the same time, I will also be mentioning these variations which come to my mind.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Table of Contents<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#regex_is_not_a_shell_pattern\">Regex Is Not a Shell Pattern<\/a><\/li><li><a href=\"#special_and_ordinary_characters_in_regular_expression\">Special and Ordinary Characters in Regular Expression<\/a><ul><li><a href=\"#ordinary_characters\">Ordinary Characters<\/a><\/li><li><a href=\"#special_characters\">Special Characters<\/a><\/li><\/ul><\/li><li><a href=\"#dot__in_regular_expression\">Dot (.) in Regular Expression<\/a><\/li><li><a href=\"#caret__in_regex\">Caret (^) in Regex<\/a><\/li><li><a href=\"#dollar__in_regex\">Dollar ($) in Regex<\/a><\/li><li><a href=\"#character_class_bracket_expression___in_regexp\">Character Class: Bracket Expression ([ ]) in Regexp<\/a><\/li><li><a href=\"#named_class_aka_named_set_in_regex\">Named Class (aka Named Set) in Regex<\/a><\/li><li><a href=\"#backslash_based_regex_b_b_w_w_s_s_gt_lt\">Backslash Based Regex (\\b, \\B, \\w, \\W, \\s, \\S, \\&gt;, \\&lt;)<\/a><\/li><li><a href=\"#repetition_operators_in_regular_expression____nm\">Repetition Operators in Regular Expression (*, +, ?, {n,m})<\/a><\/li><li><a href=\"#alternation_or_infix_operator__in_regexp\">Alternation (or Infix) Operator (|) in Regexp<\/a><\/li><li><a href=\"#grouping_in_regex\">Grouping in Regex<\/a><\/li><li><a href=\"#backreferences_in_regexp\">Back-references in Regexp<\/a><\/li><li><a href=\"#conclusion\">Conclusion<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"regex_is_not_a_shell_pattern\">Regex Is Not a Shell Pattern<\/h2>\n\n\n\n<p>I need to warn you that regexp is completely different from the zsh or bash&#8217;s glob (also called shell-pattern).<\/p>\n\n\n\n<p>For example, <code>*.mp4<\/code> in shell pattern means any filename ending with <code>.mp4<\/code>. On the other hand, the star (*) at the start of a regex is a null character.  <\/p>\n\n\n\n<p>Similarly, <code>?<\/code>, <code>()<\/code> and <code>|<\/code> have different meanings.<\/p>\n\n\n\n<p>At the same time, you need to prevent the shell from interpreting your regex as a shell pattern. For this, you need to surround it with double quotes (preferably single quotes). <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"508\" height=\"228\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-30.png?resize=508%2C228&#038;ssl=1\" alt=\"Fig: the difference between regex and shell patterns (globs)\" class=\"wp-image-1879\"\/><figcaption>Fig: the difference between regex and shell patterns (globs)<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"special_and_ordinary_characters_in_regular_expression\">Special and Ordinary Characters in Regular Expression<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ordinary_characters\">Ordinary Characters<\/h3>\n\n\n\n<p>Any character other than the .?*+{|()[\\^$ are called ordinary characters and they are interpreted as they are.<\/p>\n\n\n\n<p>For the example given below, the regex <code>linux<\/code> is made of ordinary characters and hence it is interpreted as it is.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"481\" height=\"294\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-2.png?resize=481%2C294&#038;ssl=1\" alt=\"Fig - Ordinary characters in regular expressions\" class=\"wp-image-1836\"\/><figcaption>Fig &#8211; Ordinary characters in regular expressions<\/figcaption><\/figure>\n\n\n\n<p><strong>Note: <\/strong>By the way, If a line does not contain the given regex pattern, grep does not print that line. Therefore, in the above example, the first line is omitted.   <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"special_characters\">Special Characters<\/h3>\n\n\n\n<p>The characters <code>.?*+{|()[\\^$<\/code> are called special characters (also known as <strong>metacharacters<\/strong>) since they have special meanings in the regex:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>Regular expression<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>.<\/td><td>any single character<\/td><\/tr><tr><td>*<\/td><td>the preceding item matching zero or more times<\/td><\/tr><tr><td>+<\/td><td>the preceding item matching one or more times<\/td><\/tr><tr><td>^<\/td><td>beginning of the line<\/td><\/tr><tr><td>$<\/td><td>end of the line<\/td><\/tr><tr><td>?<\/td><td>the preceding item is optional<\/td><\/tr><tr><td>[ <\/td><td>list of characters, range of characters, named classes<\/td><\/tr><tr><td>{ <\/td><td>used for interval expression <\/td><\/tr><tr><td>|<\/td><td>the infix Operator (the OR Alternate Operator)<\/td><\/tr><tr><td>(<\/td><td>used for grouping<\/td><\/tr><tr><td>\\<\/td><td>have meanings in combination with other characters; ex- \\b, \\&lt;, \\w, \\, etc.<\/td><\/tr><\/tbody><\/table><figcaption>Table: Special Characters in Regular Expression<\/figcaption><\/figure>\n\n\n\n<p>Although these characters are special characters, you can force your regex engine to treat them as ordinary characters by prepending them with a backslash. Example &#8211;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"121\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-6.png?resize=848%2C121&#038;ssl=1\" alt=\"Fig: prepend a backslash to treat metacharacters as ordinary characters\" class=\"wp-image-1841\" srcset=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-6.png?w=848&amp;ssl=1 848w, https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-6.png?resize=768%2C110&amp;ssl=1 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><figcaption>Fig: prepend a backslash to treat metacharacters as ordinary characters<\/figcaption><\/figure>\n\n\n\n<p>Now I will be explaining all these special characters in the upcoming headings with examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dot__in_regular_expression\">Dot (.) in Regular Expression<\/h2>\n\n\n\n<p>Dot will match any single character. <\/p>\n\n\n\n<p>In the following example, only &#8220;fix&#8221; from the first line is matched. Here, &#8220;i&#8221; is equated as the dot. In the second line, there is no such character between f and x and hence, nothing is matched in the second line. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"449\" height=\"240\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-3.png?resize=449%2C240&#038;ssl=1\" alt=\"Fig: Dot (.) in regexp\" class=\"wp-image-1837\"\/><figcaption>Fig: Dot (.) in regexp<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"caret__in_regex\">Caret (^) in Regex<\/h2>\n\n\n\n<p>The caret (^) means to match an empty string at the start of a line.<\/p>\n\n\n\n<p>For example, the following command searches for the &#8220;linux&#8221; at the beginning. Since the second line does not have &#8220;linux&#8221; at the start, hence that is not printed. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"493\" height=\"239\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-4.png?resize=493%2C239&#038;ssl=1\" alt=\"Fig: Caret (^) in regexp\" class=\"wp-image-1838\"\/><figcaption>Fig: Caret (^) in regexp<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dollar__in_regex\">Dollar ($) in Regex<\/h2>\n\n\n\n<p>The dollar is used to match an empty string at the end of a line. For the following example, only the second line is matched because only that one has &#8220;linux&#8221; at the end.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"506\" height=\"250\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-5.png?resize=506%2C250&#038;ssl=1\" alt=\"Figure: - Dollar ($) in regexp\" class=\"wp-image-1839\"\/><figcaption>Figure: &#8211; Dollar ($) in regexp<\/figcaption><\/figure>\n\n\n\n<p><strong>Note<\/strong>: The charet (<code>^<\/code>) and dollar (<code>$<\/code>) are also called regex anchors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"character_class_bracket_expression___in_regexp\">Character Class: Bracket Expression ([ ]) in Regexp<\/h2>\n\n\n\n<p>Character Class (also known as<strong> Character Set<\/strong>) is a list of characters in the <code>[]<\/code> to match any one character from the list. There are many types:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>[az]<\/td><td>the character \u201ca\u201d OR \u201cz\u201d<\/td><\/tr><tr><td>[a-z]<\/td><td>any letter from a to z (lowercase)<\/td><\/tr><tr><td>[A-Z]<\/td><td>any letter from A to Z (uppercase)<\/td><\/tr><tr><td>[A-Za-z]<\/td><td>any letter<\/td><\/tr><tr><td>[0-9]<\/td><td>any number<\/td><\/tr><tr><td>[-az]<\/td><td>any one character out of the three <code>-, a, z<\/code><\/td><\/tr><tr><td>[^abc]<\/td><td>negates [abc] i.e. matches any character except a, b, c (called Negated Character Class)<\/td><\/tr><\/tbody><\/table><figcaption>Table: Bracket Expressions<\/figcaption><\/figure>\n\n\n\n<p><strong>Note 1: <\/strong>Letters and numbers have different meanings in different countries and languages. The above table is for the traditional C locale. In simple words, if your work is based on English then it should work fine.<\/p>\n\n\n\n<p><strong>Explanations with examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>In the following example, regex <code>i[sn]<\/code> matches either <code>is<\/code> or <code>in<\/code>. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"506\" height=\"265\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/2022-02-26_164452.856765815.png?resize=506%2C265&#038;ssl=1\" alt=\"Fig: [sn] in regex equals to s or n.\" class=\"wp-image-1846\"\/><figcaption>Fig: [sn] equals to s or n.<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>The dash (<code>-<\/code>) is used for &#8220;Range Expression&#8221;. In the example given below, the <code>[0-9]<\/code> matches with only the digits.. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"256\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-10.png?resize=500%2C256&#038;ssl=1\" alt=\"Fig: [0-9] equals to any digit\" class=\"wp-image-1847\"\/><figcaption>Fig: <code>[0-9]<\/code> equals to any digit<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><code>[A-Za-z]<\/code>  means any alphabetic character as shown below:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"501\" height=\"301\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-12.png?resize=501%2C301&#038;ssl=1\" alt=\"Fig: [A-Za-z] equals to any alphabetic character\" class=\"wp-image-1849\"\/><figcaption>Fig: <code>[A-Za-z]<\/code> equals to any alphabetic character<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>To include the literal dash in your list as well, put the dash at the beginning in the bracket.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"414\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-13.png?resize=735%2C414&#038;ssl=1\" alt=\"Figure - including literal dash in the bracket\" class=\"wp-image-1850\"\/><figcaption>Figure &#8211; including literal dash in the bracket<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Negated Character Class<\/strong>: Continuing with the above example, <code>[^-10]<\/code> just matches any character other than the <code>-, 1, 0<\/code>. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"449\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-14.png?resize=725%2C449&#038;ssl=1\" alt=\"Figure: Negated Character Class in Regular Expression\" class=\"wp-image-1851\"\/><figcaption>Figure: Negated Character Class in Regular Expression<\/figcaption><\/figure>\n\n\n\n<p>The above-mentioned Character Classes are sufficient to create any list. But before creating any convoluted list such as <code>[A-Za-z0-9]<\/code>, you can also use also corresponding Named Classes explained below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"named_class_aka_named_set_in_regex\">Named Class (aka Named Set) in Regex<\/h2>\n\n\n\n<p><strong>Named Classes<\/strong> are predefined character classes. For example, <code>[:alpha:]<\/code> equals to any upper or lowercase alphabet<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"537\" height=\"288\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-15.png?resize=537%2C288&#038;ssl=1\" alt=\"Figure: Named Class in Regular Expression\" class=\"wp-image-1853\"\/><figcaption>Figure: Named Class in Regular Expression<\/figcaption><\/figure>\n\n\n\n<p>Here is a list of widely used named classes (source: <code><a href=\"\/\/www.gnu.org\/software\/grep\/manual\/grep.html\" target=\"_blank\" rel=\"noreferrer noopener\">man grep<\/a><\/code>, <code>man gawk<\/code>):<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>[:lower:]<\/code> &#8211; lowercase letters<\/li><li><code>[:upper:]<\/code> &#8211; uppercase letters<\/li><li><code>[:alpha:]<\/code> &#8211; alphabets<\/li><li><code>[:digit:]<\/code> &#8211; digits<\/li><li><code>[:alnum:]<\/code> &#8211; alphabets or numbers i.e. <code>[A-Za-z0-9]<\/code><\/li><li><code>[:punct:]<\/code> &#8211; punctuation characters (characters that are not letter, digits, control characters, or space characters)<\/li><li><code>[:space:]<\/code> &#8211; any space character (space, horizontal and vertical tabs, newline, carriage return, and formfeed).<\/li><li><code>[:blank:]<\/code> &#8211; space or tab<\/li><li><code>[:cntrl:]<\/code> &#8211; control characters<\/li><li><code>[:print:]<\/code> &#8211; printable characters i.e. <code>[:punct:]<\/code>,<code>[:alnum:]<\/code>, space<\/li><li><code>[:graph:]<\/code> &#8211; graphical characters i.e. <code>[:alnum:]<\/code> and <code>[:punct:]<\/code><\/li><li><code>[:xdigit:]<\/code>&#8211; hexadecimal digits<\/li><\/ul>\n\n\n\n<p><strong>Note 1: <\/strong>Special Characters lose their special meanings in the bracket. However, some of them can get it back by their special placement in the bracket. For instance, you need to place <code>^<\/code>  anywhere but first, dash (-) at first, and <code>]<\/code> at the first position to get back their special meanings. <\/p>\n\n\n\n<p><strong>Note 2:<\/strong> The Named Classes can be included with other regular expressions in the brackets. For instance, [[:upper:][:lower:]] equals both upper and lower alphabets. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"backslash_based_regex_b_b_w_w_s_s_gt_lt\">Backslash Based Regex (\\b, \\B, \\w, \\W, \\s, \\S, \\&gt;, \\&lt;)<\/h2>\n\n\n\n<p>\\w is a word-constituent character (letter, digit, or underscore). Anything other than that is \\W (non-word-constituent character). Ex &#8211; <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"622\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-16.png?resize=640%2C622&#038;ssl=1\" alt=\"Fig: \\w in regex; text credit: a brilliant StackExchange question\" class=\"wp-image-1859\"\/><figcaption>Fig: \\w in regex; text credit: a brilliant <a href=\"https:\/\/stackoverflow.com\/questions\/6664151\/difference-between-b-and-b-in-regex\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">StackExchange question<\/a><\/figcaption><\/figure>\n\n\n\n<p><code>\\s<\/code> is <code>[[:space:]]<\/code> mentioned above. <code>\\S<\/code> (non-whitespace) is the exact opposite.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"624\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-17.png?resize=666%2C624&#038;ssl=1\" alt=\"Fig: \\s and \\S in regex\" class=\"wp-image-1860\"\/><figcaption>Fig: <code>\\s<\/code> and <code>\\S<\/code> in regex; see how the regex is not matching the empty line.<\/figcaption><\/figure>\n\n\n\n<p><code>\\b<\/code> equals to an empty string at the edge of a word (source: <a href=\"https:\/\/www.gnu.org\/software\/grep\/manual\/grep.html\" target=\"_blank\" rel=\"noreferrer noopener\">grep&#8217;s manual<\/a>). <strong>In GNU gawk command of Linux, it is <code>\\y<\/code>.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"623\" height=\"485\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-19.png?resize=623%2C485&#038;ssl=1\" alt=\"Figure: \\b in regular expression\" class=\"wp-image-1862\"\/><figcaption>Figure: <code>\\b<\/code> in regular expression<\/figcaption><\/figure>\n\n\n\n<p>\\B matches to an empty string provided it\u2019s not at the edge of a word. (source: <code>man grep<\/code>)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"426\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-20.png?resize=640%2C426&#038;ssl=1\" alt=\"Figure: \\B in regex\" class=\"wp-image-1863\"\/><figcaption>Figure: <code>\\B<\/code> in regex<\/figcaption><\/figure>\n\n\n\n<p><code>\\&lt;<\/code> and <code>\\&gt;<\/code> match the empty string at the beginning and end of a word (respectively).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"634\" height=\"493\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-21.png?resize=634%2C493&#038;ssl=1\" alt=\"Figure: \\< in regular expression\" class=\"wp-image-1864\"\/><figcaption>Figure: <code>\\&lt;<\/code> in regular expression<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"repetition_operators_in_regular_expression____nm\">Repetition Operators in Regular Expression (*, +, ?, {n,m})<\/h2>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>Regular expression<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>?<\/td><td>the preceding item is optional<\/td><\/tr><tr><td>*<\/td><td>the preceding item matching zero or more times<\/td><\/tr><tr><td>+<\/td><td>the preceding item matching one or more times<\/td><\/tr><tr><td>{n}<\/td><td>the preceding item matching exactly n times<\/td><\/tr><tr><td>{n,}<\/td><td>the preceding item matching n or more times<\/td><\/tr><tr><td>{,m}<\/td><td>the preceding item matching m or less than m times<\/td><\/tr><tr><td>{n,m}<\/td><td>the preceding item matching n to m times<\/td><\/tr><\/tbody><\/table><figcaption>Table: Repetition Regex; source: grep&#8217;s man page<\/figcaption><\/figure>\n\n\n\n<p>Now I will describe them with examples.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Star (*)<\/strong>: In the following example, &#8220;<code>f.*x<\/code>&#8221; means &#8220;f, then any character (.) repeated zero or more times (*), and then x&#8221;.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"457\" height=\"270\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-22.png?resize=457%2C270&#038;ssl=1\" alt=\"Figure: regex star (*)\" class=\"wp-image-1870\"\/><figcaption>Figure: regex star (*)<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Plus (+)<\/strong>: Similarly, &#8220;<code>f.+x<\/code>&#8221; means &#8220;f, then any character (.) repeated one or more times (+), and then x&#8221;. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"244\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-23.png?resize=454%2C244&#038;ssl=1\" alt=\"Figure: Plus (+) in regex\" class=\"wp-image-1872\"\/><figcaption>Figure: Plus (+) in regex<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Question Mark (?)<\/strong> in regex makes previous item optional. Therefore, in the following example, <code>https?<\/code> matches with both <code>http<\/code> and <code>https<\/code>:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"266\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-24.png?resize=480%2C266&#038;ssl=1\" alt=\"Figure: Question mark (?) in regex\" class=\"wp-image-1873\"\/><figcaption>Figure: Question mark (?) in regex<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>{n}:<\/strong> For the following example, <code>.{5}<\/code> means any character (dot) repeated 5 times. Therefore, first grep prints any 5 character. Then it prints another 5 character from the remaining part. And then again it prints the next 5 character. Now, the text does not have 5 character left and hence nothing is printed. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"164\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-25.png?resize=766%2C164&#038;ssl=1\" alt=\"Figure: Curly braces {n} in regex\" class=\"wp-image-1874\"\/><figcaption>Figure: Curly braces {n} in regex<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>{n,},{,m},{n,m}<\/strong>, similarly, means the preceding item repeated n or more, m or less, n to m times respectively.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"184\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-26.png?resize=785%2C184&#038;ssl=1\" alt=\"Figure: curly braces {,m} in regex\" class=\"wp-image-1875\" srcset=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-26.png?w=785&amp;ssl=1 785w, https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-26.png?resize=768%2C180&amp;ssl=1 768w\" sizes=\"(max-width: 785px) 100vw, 785px\" \/><figcaption>Figure: curly braces {,m} in regex<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"alternation_or_infix_operator__in_regexp\">Alternation (or Infix) Operator (|) in Regexp<\/h2>\n\n\n\n<p>When you insert an Infix Operator <code>|<\/code> between two regular expressions, the regex engine chooses one of the two expressions.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"339\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-28.png?resize=553%2C339&#038;ssl=1\" alt=\"Fig: Infix (Alternate) Operator In Regexp\" class=\"wp-image-1877\"\/><figcaption>Fig: Infix (Alternate) Operator In Regexp<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"grouping_in_regex\">Grouping in Regex<\/h2>\n\n\n\n<p>You can put a group of characters in parenthesis and force the regex engine to treat them as a unit. <\/p>\n\n\n\n<p>For instance, in the following example, a group of characters <code>smart<\/code> is repeated twice. On the other hand, regex <code>smart2<\/code> means <code>smartt<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"117\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/image-29.png?resize=725%2C117&#038;ssl=1\" alt=\"Figure: Parenthesis to group the regex\" class=\"wp-image-1878\"\/><figcaption>Figure: Parenthesis to group the regex<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"backreferences_in_regexp\">Back-references in Regexp<\/h2>\n\n\n\n<p>Back-references in a regex are denoted by <code>\\n<\/code>, where n is a number and they &#8220;refer back&#8221; to the nth parenthesized regex.<\/p>\n\n\n\n<p>For example given below, <code>\\2<\/code> refers to the second parenthesized part i.e. tech and <code>\\1<\/code> to the first parenthesized part i.e. smart. In other words, <code>\\2<\/code> is replaced with the second one and <code>\\1<\/code> with the first. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"245\" src=\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/03\/image-4.png?resize=689%2C245&#038;ssl=1\" alt=\"Backreferences in regexp\" class=\"wp-image-1929\"\/><figcaption>Figure: Backreferences in regexp<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>That&#8217;s all folks. If you want to revise it quickly, just have a quick look at the given tables. <\/p>\n\n\n\n<p>Thanks for reading and if you have any suggestions\/problems, please comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is about regular expression (aka regex, regexp) &#8211; anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.<\/p>\n","protected":false},"author":2,"featured_media":1880,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17],"tags":[34,18,31,33],"class_list":["post-1804","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line-tools","tag-basic","tag-command-line-tools","tag-grep","tag-sed"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Regular Expression (Regex, and Regexp) in Linux Ft. Grep | SmartTech101<\/title>\n<meta name=\"description\" content=\"This is about regular expression (aka regex, regexp) - anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Regular Expression (Regex, and Regexp) in Linux Ft. Grep | SmartTech101\" \/>\n<meta property=\"og:description\" content=\"This is about regular expression (aka regex, regexp) - anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\" \/>\n<meta property=\"og:site_name\" content=\"SmartTech101\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-02T11:36:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-04T01:20:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ajay\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ajay_yadav\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ajay\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\"},\"author\":{\"name\":\"Ajay\",\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/2edfee738a82f9c963210f8cdb438334\"},\"headline\":\"Regular Expression (Regex, and Regexp) in Linux Ft. Grep\",\"datePublished\":\"2022-03-02T11:36:15+00:00\",\"dateModified\":\"2022-03-04T01:20:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\"},\"wordCount\":1651,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/e8d5aebc510d698e11e9df6291381633\"},\"image\":{\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1\",\"keywords\":[\"basic\",\"Command Line Tools\",\"grep\",\"sed\"],\"articleSection\":[\"Command Line Tools\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\",\"url\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\",\"name\":\"Regular Expression (Regex, and Regexp) in Linux Ft. Grep | SmartTech101\",\"isPartOf\":{\"@id\":\"https:\/\/smarttech101.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1\",\"datePublished\":\"2022-03-02T11:36:15+00:00\",\"dateModified\":\"2022-03-04T01:20:20+00:00\",\"description\":\"This is about regular expression (aka regex, regexp) - anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.\",\"breadcrumb\":{\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1\",\"width\":1280,\"height\":720,\"caption\":\"regular expression (regex, regexp) in Linux\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/smarttech101.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Regular Expression (Regex, and Regexp) in Linux Ft. Grep\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/smarttech101.com\/#website\",\"url\":\"https:\/\/smarttech101.com\/\",\"name\":\"SmartTech101\",\"description\":\"Do Everything in Linux\",\"publisher\":{\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/e8d5aebc510d698e11e9df6291381633\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/smarttech101.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/e8d5aebc510d698e11e9df6291381633\",\"name\":\"Ajay Yadav\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/09\/cropped-ST101_logo.png?fit=180%2C60&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/09\/cropped-ST101_logo.png?fit=180%2C60&ssl=1\",\"width\":180,\"height\":60,\"caption\":\"Ajay Yadav\"},\"logo\":{\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/2edfee738a82f9c963210f8cdb438334\",\"name\":\"Ajay\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/smarttech101.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6eea348caae2173954765a7cdf6cd107?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6eea348caae2173954765a7cdf6cd107?s=96&d=mm&r=g\",\"caption\":\"Ajay\"},\"sameAs\":[\"https:\/\/x.com\/ajay_yadav\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Regular Expression (Regex, and Regexp) in Linux Ft. Grep | SmartTech101","description":"This is about regular expression (aka regex, regexp) - anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/","og_locale":"en_US","og_type":"article","og_title":"Regular Expression (Regex, and Regexp) in Linux Ft. Grep | SmartTech101","og_description":"This is about regular expression (aka regex, regexp) - anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.","og_url":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/","og_site_name":"SmartTech101","article_published_time":"2022-03-02T11:36:15+00:00","article_modified_time":"2022-03-04T01:20:20+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png","type":"image\/png"}],"author":"Ajay","twitter_card":"summary_large_image","twitter_creator":"@ajay_yadav","twitter_misc":{"Written by":"Ajay","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#article","isPartOf":{"@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/"},"author":{"name":"Ajay","@id":"https:\/\/smarttech101.com\/#\/schema\/person\/2edfee738a82f9c963210f8cdb438334"},"headline":"Regular Expression (Regex, and Regexp) in Linux Ft. Grep","datePublished":"2022-03-02T11:36:15+00:00","dateModified":"2022-03-04T01:20:20+00:00","mainEntityOfPage":{"@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/"},"wordCount":1651,"commentCount":1,"publisher":{"@id":"https:\/\/smarttech101.com\/#\/schema\/person\/e8d5aebc510d698e11e9df6291381633"},"image":{"@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1","keywords":["basic","Command Line Tools","grep","sed"],"articleSection":["Command Line Tools"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/","url":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/","name":"Regular Expression (Regex, and Regexp) in Linux Ft. Grep | SmartTech101","isPartOf":{"@id":"https:\/\/smarttech101.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage"},"image":{"@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1","datePublished":"2022-03-02T11:36:15+00:00","dateModified":"2022-03-04T01:20:20+00:00","description":"This is about regular expression (aka regex, regexp) - anchors (dot and dollar), brackets ((,[,{), named class, alternation, back-references.","breadcrumb":{"@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#primaryimage","url":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1","contentUrl":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1","width":1280,"height":720,"caption":"regular expression (regex, regexp) in Linux"},{"@type":"BreadcrumbList","@id":"https:\/\/smarttech101.com\/regular-expression-regex-and-regexp-in-linux-ft-grep\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smarttech101.com\/"},{"@type":"ListItem","position":2,"name":"Regular Expression (Regex, and Regexp) in Linux Ft. Grep"}]},{"@type":"WebSite","@id":"https:\/\/smarttech101.com\/#website","url":"https:\/\/smarttech101.com\/","name":"SmartTech101","description":"Do Everything in Linux","publisher":{"@id":"https:\/\/smarttech101.com\/#\/schema\/person\/e8d5aebc510d698e11e9df6291381633"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smarttech101.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smarttech101.com\/#\/schema\/person\/e8d5aebc510d698e11e9df6291381633","name":"Ajay Yadav","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smarttech101.com\/#\/schema\/person\/image\/","url":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/09\/cropped-ST101_logo.png?fit=180%2C60&ssl=1","contentUrl":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/09\/cropped-ST101_logo.png?fit=180%2C60&ssl=1","width":180,"height":60,"caption":"Ajay Yadav"},"logo":{"@id":"https:\/\/smarttech101.com\/#\/schema\/person\/image\/"}},{"@type":"Person","@id":"https:\/\/smarttech101.com\/#\/schema\/person\/2edfee738a82f9c963210f8cdb438334","name":"Ajay","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smarttech101.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6eea348caae2173954765a7cdf6cd107?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6eea348caae2173954765a7cdf6cd107?s=96&d=mm&r=g","caption":"Ajay"},"sameAs":["https:\/\/x.com\/ajay_yadav"]}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/smarttech101.com\/wp-content\/uploads\/2022\/02\/regular-expression-regex-regexp-in-linux.png?fit=1280%2C720&ssl=1","_links":{"self":[{"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/posts\/1804"}],"collection":[{"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/comments?post=1804"}],"version-history":[{"count":5,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/posts\/1804\/revisions"}],"predecessor-version":[{"id":1930,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/posts\/1804\/revisions\/1930"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/media\/1880"}],"wp:attachment":[{"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/media?parent=1804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/categories?post=1804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smarttech101.com\/wp-json\/wp\/v2\/tags?post=1804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}