{"id":2270,"date":"2016-12-12T17:15:31","date_gmt":"2016-12-12T15:15:31","guid":{"rendered":"http:\/\/www.systemcodegeeks.com\/?p=2270"},"modified":"2017-12-04T16:12:14","modified_gmt":"2017-12-04T14:12:14","slug":"bash-regular-expressions-example","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/","title":{"rendered":"Bash Regular Expressions Example"},"content":{"rendered":"<p>A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using various operators to combine smaller expressions.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;SG9vnnKgRCD7iZxf&#8217;]<br \/>\n&nbsp;<br \/>\nThe fundamental building blocks are the regular expressions that match a single character. Most characters, including all letters and digits, are regular expressions that match themselves. Any metacharacter with special meaning may be quoted by preceding it with a backslash.<\/p>\n<p>The following table shows an overview of the whole article:<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#meta\">1. Regular expression metacharacters<\/a><\/dt>\n<dt><a href=\"#grep\">2. Examples using grep<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#grep_line\">2.1 Line and word anchors<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#grep_char\">2.2 Character classes<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#grep_wild\">2.3 Wildcards<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#pattern\">3. Pattern matching using Bash features<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#pattern_char\">3.1 Character ranges<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#pattern_class\">3.2 Character classes<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#summary\">4. Summary<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"meta\"><\/a>1. Regular expression metacharacters<\/h2>\n<p>A regular expression may be followed by one of several repetition operators (metacharacters):<\/p>\n<table>\n<tbody>\n<tr>\n<th>Operator<\/th>\n<th>Effect<\/th>\n<\/tr>\n<tr>\n<td>.<\/td>\n<td>Matches any single character.<\/td>\n<\/tr>\n<tr>\n<td>?<\/td>\n<td>The preceding item is optional and will be matched, at most, once.<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>The preceding item will be matched zero or more times.<\/td>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>The preceding item will be matched one or more times.<\/td>\n<\/tr>\n<tr>\n<td>{N}<\/td>\n<td>The preceding item is matched exactly N times.<\/td>\n<\/tr>\n<tr>\n<td>{N,}<\/td>\n<td>The preceding item is matched N or more times.<\/td>\n<\/tr>\n<tr>\n<td>{N,M}<\/td>\n<td>The preceding item is matched at least N times, but not more than M times.<\/td>\n<\/tr>\n<tr>\n<td>&#8211;<\/td>\n<td>represents the range if it&#8217;s not first or last in a list or the ending point of a range in a list.<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>Matches the empty string at the beginning of a line; also represents the characters not in the range of a list.<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>Matches the empty string at the end of a line.<\/td>\n<\/tr>\n<tr>\n<td>\\b<\/td>\n<td>Matches the empty string at the edge of a word.<\/td>\n<\/tr>\n<tr>\n<td>\\B<\/td>\n<td>Matches the empty string provided it&#8217;s not at the edge of a word.<\/td>\n<\/tr>\n<tr>\n<td>\\&lt;<\/td>\n<td>Match the empty string at the beginning of word.<\/td>\n<\/tr>\n<tr>\n<td>\\&gt;<\/td>\n<td>Match the empty string at the end of word.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings that respectively match the concatenated subexpressions.<\/p>\n<p>Two regular expressions may be joined by the infix operator &#8220;|&#8221;. The resulting regular expression matches any string matching either subexpression.<\/p>\n<p>Repetition takes precedence over concatenation, which in turn takes precedence over alternation. A whole subexpression may be enclosed in parentheses to override these precedence rules.<\/p>\n<h2><a name=\"grep\"><\/a>2. Examples using grep<\/h2>\n<p>The command grep searches the input files for lines containing a match to a given pattern list. When it finds a match in a line, it copies the line to standard output (by default), or whatever other sort of output you have requested with options.<\/p>\n<p>Though grep expects to do the matching on text, it has no limits on input line length other than available memory, and it can match arbitrary characters within a line. If the final byte of an input file is not a newline, grep silently supplies one. Since newline is also a separator for the list of patterns, there is no way to match newline characters in a text.<\/p>\n<p>The following Textfile will be used for the next examples:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Text.txt<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false\"> \r\nWe shall not spend a large expense of time\r\nBefore we reckon with your several loves,\r\nAnd make us even with you. My thanes and kinsmen,\r\nHenceforth be earls, the first that ever Scotland\r\nIn such an honour named. What's more to do,\r\nWhich would be planted newly with the time,\r\nAs calling home our exiled friends abroad\r\nThat fled the snares of watchful tyranny;\r\nProducing forth the cruel ministers\r\nOf this dead butcher and his fiend-like queen,\r\nWho, as 'tis thought, by self and violent hands\r\nTook off her life; this, and what needful else\r\nThat calls upon us, by the grace of Grace,\r\nWe will perform in measure, time and place:\r\nSo, thanks to all at once and to each one,\r\nWhom we invite to see us crown'd at Scone.\r\nMacbeth, William Shakespeare\r\n<\/pre>\n<p>With the first command, the lines from Test.txt containing the string with will be displayed.<\/p>\n<p>The next command displays the line numbers containing this search string.<\/p>\n<figure id=\"attachment_2281\" aria-describedby=\"caption-attachment-2281\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp01-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2281\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp01-1.jpg\" alt=\"A simple Regular Expression Example using grep\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp01-1.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp01-1-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2281\" class=\"wp-caption-text\">A simple Regular Expression Example using grep<\/figcaption><\/figure>\n<h3><a name=\"grep_line\"><\/a>2.1 Line and word anchors<\/h3>\n<p>In the following example, we now exclusively want to display lines starting with the string &#8220;We&#8221;.<\/p>\n<p>In the next example, we search for lines ending in &#8220;:&#8221;.<\/p>\n<figure id=\"attachment_2275\" aria-describedby=\"caption-attachment-2275\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp02.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2275\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp02.jpg\" alt=\"A Regular Expression Line Anchor Example\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp02.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp02-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2275\" class=\"wp-caption-text\">A Regular Expression Line Anchor Example<\/figcaption><\/figure>\n<h3><a name=\"grep_char\"><\/a>2.2 Character classes<\/h3>\n<p>A bracket expression is a list of characters enclosed by &#8220;[&#8221; and &#8220;]&#8221;. It matches any single character in that list.<\/p>\n<p>If the first character of the list is the caret, &#8220;^&#8221;, then it matches any character NOT in the list. For example, the regular expression &#8220;[0123456789]&#8221; matches any single digit.<\/p>\n<p>Within a bracket expression, a range expression consists of two characters separated by a hyphen. It matches any single character that sorts between the two characters, inclusive, using the locale&#8217;s collating sequence and character set.<\/p>\n<p>For example, in the default C locale, &#8220;[a-d]&#8221; is equivalent to &#8220;[abcd]&#8221;. Many locales sort characters in dictionary order, and in these locales &#8220;[a-d]&#8221; is typically not equivalent to &#8220;[abcd]&#8221;; it might be equivalent to &#8220;[aBbCcDd]&#8221;, for example.<\/p>\n<p>To obtain the traditional interpretation of bracket expressions, you can use the C locale by setting the LC_ALL environment variable to the value &#8220;C&#8221;.<\/p>\n<p>In the following example, all the lines containing either a &#8220;y&#8221; or &#8220;c&#8221; character are displayed:<\/p>\n<figure id=\"attachment_2276\" aria-describedby=\"caption-attachment-2276\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp03.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2276\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp03.jpg\" alt=\"A Regular Expression Character Class Example\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp03.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp03-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2276\" class=\"wp-caption-text\">A Regular Expression Character Class Example<\/figcaption><\/figure>\n<h3><a name=\"grep_wild\"><\/a>2.3 Wildcards<\/h3>\n<p>Use the &#8220;.&#8221; for a single character match. If you want to get a list of all five-character English dictionary words starting with &#8220;c&#8221; and ending in &#8220;s&#8221; (handy for solving crosswords):<\/p>\n<figure id=\"attachment_2277\" aria-describedby=\"caption-attachment-2277\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp04.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2277\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp04.jpg\" alt=\"A Regular Expression Wildcards Example\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp04.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp04-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2277\" class=\"wp-caption-text\">A Regular Expression Wildcards Example<\/figcaption><\/figure>\n<p>If you want to display lines containing the literal dot character, use the -F option to grep.<\/p>\n<p>For matching multiple characters, use the asterisk. This example selects all words starting with &#8220;c&#8221; and ending in &#8220;s&#8221; from the system&#8217;s dictionary:<\/p>\n<figure id=\"attachment_2278\" aria-describedby=\"caption-attachment-2278\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp05.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2278\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp05.jpg\" alt=\"A Regular Expression Wildcards Example\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp05.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp05-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2278\" class=\"wp-caption-text\">A Regular Expression Wildcards Example<\/figcaption><\/figure>\n<h2><a name=\"pattern\"><\/a>3. Pattern matching using Bash features<\/h2>\n<h3><a name=\"pattern_char\"><\/a>3.1 Character ranges<\/h3>\n<p>Apart from grep and regular expressions, there&#8217;s a good deal of pattern matching that you can do directly in the shell, without having to use an external program.<\/p>\n<p>As you already know, the asterisk (*) and the question mark (?) match any string or any single character, respectively. Quote these special characters to match them literally:<\/p>\n<figure id=\"attachment_2279\" aria-describedby=\"caption-attachment-2279\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp06.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2279\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp06.jpg\" alt=\"A Regular Expression Character Range Example\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp06.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp06-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2279\" class=\"wp-caption-text\">A Regular Expression Character Range Example<\/figcaption><\/figure>\n<p>This lists all files in the current directory, starting with &#8220;A&#8221;, &#8220;B&#8221; or &#8220;C&#8221;.<\/p>\n<p>If the first character within the braces is &#8220;!&#8221; or &#8220;^&#8221;, any character not enclosed will be matched. To match the dash (&#8220;-&#8220;), include it as the first or last character in the set.<\/p>\n<p>The sorting depends on the current locale and of the value of the LC_COLLATE variable, if it is set. Mind that other locales might interpret &#8220;[a-cx-z]&#8221; as &#8220;[aBbCcXxYyZz]&#8221; if sorting is done in dictionary order.<\/p>\n<p>If you want to be sure to have the traditional interpretation of ranges, force this behavior by setting LC_COLLATE or LC_ALL to &#8220;C&#8221;.<\/p>\n<h3><a name=\"pattern_class\"><\/a>3.2 Character classes<\/h3>\n<p>Character classes can be specified within the square braces, using the syntax [:CLASS:], where CLASS is defined in the POSIX standard and has one of the values:<\/p>\n<ul>\n<li>alnum<\/li>\n<li>alpha<\/li>\n<li>ascii<\/li>\n<li>blank<\/li>\n<li>cntrl<\/li>\n<li>digit<\/li>\n<li>graph<\/li>\n<li>lower<\/li>\n<li>print<\/li>\n<li>punct<\/li>\n<li>space<\/li>\n<li>upper<\/li>\n<li>word<\/li>\n<li>xdigit<\/li>\n<\/ul>\n<p>In the following example are all Files listed, which Begins with an Uppercase letter.<\/p>\n<figure id=\"attachment_2280\" aria-describedby=\"caption-attachment-2280\" style=\"width: 641px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp07.jpg\"><img decoding=\"async\" class=\"size-full wp-image-2280\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp07.jpg\" alt=\"A Regular Expression Character Class Example\" width=\"641\" height=\"427\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp07.jpg 641w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/12\/RegExp07-300x200.jpg 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/a><figcaption id=\"caption-attachment-2280\" class=\"wp-caption-text\">A Regular Expression Character Class Example<\/figcaption><\/figure>\n<p>When the extglob shell option is enabled (using the shopt built-in), several extended pattern matching operators are recognized.<\/p>\n<h2><a name=\"summary\"><\/a>4. Summary<\/h2>\n<p>Regular expressions are powerful tools for selecting particular lines from files or output. A lot of UNIX commands use regular expressions: vim, perl, the PostgreSQL database and so on.<\/p>\n<p>They can be made available in any language or application using external libraries, and they even found their way to non-UNIX systems. For instance, regular expressions are used in the Excell spreadsheet that comes with the MicroSoft Windows Office suite.<\/p>\n<p>In this chapter we got the feel of the grep command, which is indispensable in any UNIX environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using various operators to combine smaller expressions. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ulp id=&#8217;SG9vnnKgRCD7iZxf&#8217;] &nbsp; The fundamental building blocks are the regular expressions that match a single character. Most characters, &hellip;<\/p>\n","protected":false},"author":35,"featured_media":185,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[87],"class_list":["post-2270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","tag-regular-expression"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Bash Regular Expressions Example - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash Regular Expressions Example - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-12T15:15:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-04T14:12:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andreas Pomarolli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andreas Pomarolli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\"},\"author\":{\"name\":\"Andreas Pomarolli\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574\"},\"headline\":\"Bash Regular Expressions Example\",\"datePublished\":\"2016-12-12T15:15:31+00:00\",\"dateModified\":\"2017-12-04T14:12:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\"},\"wordCount\":1227,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"keywords\":[\"Regular Expression\"],\"articleSection\":[\"BASH\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\",\"name\":\"Bash Regular Expressions Example - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"datePublished\":\"2016-12-12T15:15:31+00:00\",\"dateModified\":\"2017-12-04T14:12:14+00:00\",\"description\":\"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Shell Scripting\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"BASH\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/bash\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Bash Regular Expressions Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574\",\"name\":\"Andreas Pomarolli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g\",\"caption\":\"Andreas Pomarolli\"},\"description\":\"Andreas has graduated from Computer Science and Bioinformatics at the University of Linz. During his studies he has been involved with a large number of research projects ranging from software engineering to data engineering and at least web engineering. His scientific focus includes the areas of software engineering, data engineering, web engineering and project management. He currently works as a software engineer in the IT sector where she is mainly involved with projects based on Java, Databases and Web Technologies.\",\"sameAs\":[\"https:\/\/www.systemcodegeeks.com\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/andreas-pomarolli\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bash Regular Expressions Example - System Code Geeks - 2026","description":"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using","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:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/","og_locale":"en_US","og_type":"article","og_title":"Bash Regular Expressions Example - System Code Geeks - 2026","og_description":"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using","og_url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_published_time":"2016-12-12T15:15:31+00:00","article_modified_time":"2017-12-04T14:12:14+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","type":"image\/jpeg"}],"author":"Andreas Pomarolli","twitter_card":"summary_large_image","twitter_creator":"@systemcodegeeks","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Andreas Pomarolli","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/"},"author":{"name":"Andreas Pomarolli","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574"},"headline":"Bash Regular Expressions Example","datePublished":"2016-12-12T15:15:31+00:00","dateModified":"2017-12-04T14:12:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/"},"wordCount":1227,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","keywords":["Regular Expression"],"articleSection":["BASH"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/","url":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/","name":"Bash Regular Expressions Example - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","datePublished":"2016-12-12T15:15:31+00:00","dateModified":"2017-12-04T14:12:14+00:00","description":"A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/bash-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/shell-scripting\/bash\/bash-regular-expressions-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Shell Scripting","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/"},{"@type":"ListItem","position":3,"name":"BASH","item":"https:\/\/www.systemcodegeeks.com\/category\/shell-scripting\/bash\/"},{"@type":"ListItem","position":4,"name":"Bash Regular Expressions Example"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/add1d14bc9f6218cde89909a5d3cc574","name":"Andreas Pomarolli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e36c8f6d54df9db449aa16b2d6ddc1077d50d5e1ff3be0f0b6809081138f01fd?s=96&d=mm&r=g","caption":"Andreas Pomarolli"},"description":"Andreas has graduated from Computer Science and Bioinformatics at the University of Linz. During his studies he has been involved with a large number of research projects ranging from software engineering to data engineering and at least web engineering. His scientific focus includes the areas of software engineering, data engineering, web engineering and project management. He currently works as a software engineer in the IT sector where she is mainly involved with projects based on Java, Databases and Web Technologies.","sameAs":["https:\/\/www.systemcodegeeks.com"],"url":"https:\/\/www.systemcodegeeks.com\/author\/andreas-pomarolli\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/2270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=2270"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/2270\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/185"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=2270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=2270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=2270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}