{"id":289,"date":"2026-04-28T09:00:00","date_gmt":"2026-04-28T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/"},"modified":"2026-10-10T21:20:58","modified_gmt":"2026-10-10T15:50:58","slug":"go-regular-expressions-regexp","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/","title":{"rendered":"Go Regular Expressions with the regexp Package"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go regular expressions let you search, check and change text using patterns instead of exact words. In this post, you will match text and find every number in a sentence. Then you will pull out parts with capture groups and replace text. Also, each idea comes with a short example that you can run yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Patterns work on text, so first review <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-examples\/\">Go strings explained with examples<\/a>. We also write patterns inside backticks, the raw strings from that lesson. Finally, we check errors as shown in <a href=\"https:\/\/smitabharat.com\/blog\/go-error-handling-guide\/\">error handling in Go for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Regular Expressions?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In short, a regular expression, or regex, is a tiny language for describing text. For example, <code>\\d+<\/code> means &#8220;one or more digits&#8221;, and <code>^go<\/code> means &#8220;starts with go&#8221;. Think of it as a search with wildcards that understands shapes, such as &#8220;an email&#8221; or &#8220;a date&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go regular expressions come from the <code>regexp<\/code> package. Specifically, it uses the RE2 syntax, which always runs in linear time. In other words, a bad pattern can never freeze your server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>matched, err := regexp.MatchString(`^go`, \"golang\")\nfmt.Println(matched, err) \/\/ true &lt;nil&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Compile Once, Use Many Times<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>re := regexp.MustCompile(`\\d+`)\n\nfmt.Println(re.MatchString(\"order 42\"))                     \/\/ true\nfmt.Println(re.FindString(\"order 42 and 7\"))                \/\/ 42\nfmt.Println(re.FindAllString(\"order 42 and 7 and 1000\", -1)) \/\/ [42 7 1000]\nfmt.Println(re.FindStringIndex(\"order 42\"))                 \/\/ [6 8]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, compiling a pattern takes work. So compile it once, often as a package-level variable, and reuse it. <code>MustCompile<\/code> panics on a bad pattern, which is fine for fixed patterns in your code. For user-supplied patterns, however, use <code>regexp.Compile<\/code> and check the error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Validating Input with Go Regular Expressions<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>email := regexp.MustCompile(`^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$`)\n\nfmt.Println(email.MatchString(\"asha@example.com\")) \/\/ true\nfmt.Println(email.MatchString(\"bad@email\"))        \/\/ false\nfmt.Println(email.MatchString(\"Ravi@Example.com\")) \/\/ false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, the <code>^<\/code> and <code>$<\/code> anchors force the whole text to match, not just a part. Notice the last result too. The pattern only allows small letters, so add <code>(?i)<\/code> at the start to ignore case.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Capture Groups: Pulling Out Parts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, parentheses mark parts of the match that you want to keep. For example, the diagram below shows a date pattern split into three groups.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-diagram-1024x640.png\" alt=\"Go Regular Expressions diagram showing a date pattern with three capture groups and the matched parts\" class=\"wp-image-269\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Each pair of parentheses captures one part of the date, and FindStringSubmatch returns the full match followed by every group.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>date := regexp.MustCompile(`(\\d{4})-(\\d{2})-(\\d{2})`)\nm := date.FindStringSubmatch(\"Released on 2026-08-20.\")\nfmt.Println(m)      \/\/ [2026-08-20 2026 08 20]\nfmt.Println(len(m)) \/\/ 4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First of all, index 0 holds the full match, and the groups follow in order. So <code>m[1]<\/code> is the year, <code>m[2]<\/code> the month and <code>m[3]<\/code> the day.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Named Groups<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>named := regexp.MustCompile(`(?P&lt;year&gt;\\d{4})-(?P&lt;month&gt;\\d{2})`)\nmm := named.FindStringSubmatch(\"2026-08\")\nfmt.Println(mm[named.SubexpIndex(\"year\")], mm[named.SubexpIndex(\"month\")]) \/\/ 2026 08<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, names make long patterns easier to read. In addition, your code no longer breaks when someone adds a new group in the middle.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Replacing Text with Go Regular Expressions<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>fmt.Println(date.ReplaceAllString(\"2026-08-20\", \"$3\/$2\/$1\")) \/\/ 20\/08\/2026\n\nspaces := regexp.MustCompile(`\\s+`)\nfmt.Println(spaces.ReplaceAllString(\"too    many   spaces\", \" \")) \/\/ too many spaces\n\nfmt.Println(regexp.QuoteMeta(\"1+1=2?\")) \/\/ 1\\+1=2\\?<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, in the replacement, <code>$1<\/code>, <code>$2<\/code> and <code>$3<\/code> refer to the groups. <code>QuoteMeta<\/code> escapes special characters, so user text matches literally.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Regular Expressions Cheat Sheet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\\d       a digit                         7\n\\w       a letter, digit or underscore   a\n\\s       a space, tab or newline\n+        one or more                     \\d+ matches 2026\n*        zero or more                    a* matches aaa\n?        optional                        colou?r matches color\n{2,}     two or more                     [a-z]{2,} matches com\n^ $      start and end                   ^go$ matches go only<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">When Not to Use Go Regular Expressions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Regex is powerful, but it is not always the best tool. For simple checks, the strings package is faster and easier to read. For example, <code>strings.HasPrefix(s, \"go\")<\/code> beats <code>^go<\/code>, and <code>strings.Contains<\/code> beats a plain word pattern.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, avoid Go regular expressions for structured formats such as JSON, HTML or full email rules. After all, real parsers handle those edge cases far better. In short, reach for regex when the text has a clear shape but no proper parser exists.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Regular Expressions<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>error parsing regexp: invalid or unsupported Perl syntax: <code>(?=<\/code><\/td><td>Because RE2 has no lookahead.<\/td><td>So use capture groups or extra code.<\/td><\/tr><tr><td>error parsing regexp: missing closing ): <code>(abc<\/code><\/td><td>Because a bracket is missing.<\/td><td>So balance every parenthesis.<\/td><\/tr><tr><td>Pattern matches inside a word<\/td><td>Because anchors are missing.<\/td><td>So add <code>^<\/code> and <code>$<\/code>, or <code>\\b<\/code>.<\/td><\/tr><tr><td>Backslashes vanish<\/td><td>Because the pattern used double quotes.<\/td><td>So use backticks for patterns.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Regex puzzles also appear in coding interviews. So practise with my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they stay accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/regexp\">regexp package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/regexp\/syntax\">regexp\/syntax: supported syntax<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go regular expressions live in the <code>regexp<\/code> package and use RE2 syntax.<\/li>\n\n\n\n<li>Compile once with <code>MustCompile<\/code> and reuse the pattern.<\/li>\n\n\n\n<li>Use <code>^<\/code> and <code>$<\/code> to match the whole text.<\/li>\n\n\n\n<li>Capture groups and <code>FindStringSubmatch<\/code> pull out parts.<\/li>\n\n\n\n<li>RE2 has no lookahead, but it never hangs on bad input.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, you can search and reshape text with patterns. Next, we will make our programs easier to debug with structured logging using log\/slog.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/\">Go Structured Logging with log\/slog<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go regular expressions let you search, check and change text using patterns instead of exact words. In this post, you will match text and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":268,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,55,23,21],"swapz_series":[],"class_list":["post-289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-regex","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Regular Expressions with the regexp Package<\/title>\n<meta name=\"description\" content=\"Learn Go regular expressions with simple examples: match, find and replace text, use capture groups and avoid the common RE2 syntax errors.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Regular Expressions with the regexp Package\" \/>\n<meta property=\"og:description\" content=\"Learn Go regular expressions with simple examples: match, find and replace text, use capture groups and avoid the common RE2 syntax errors.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-28T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Regular Expressions with the regexp Package\",\"datePublished\":\"2026-04-28T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/\"},\"wordCount\":670,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-regular-expressions-regexp-featured.png\",\"keywords\":[\"Go Lang\",\"Go Regex\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/\",\"name\":\"Go Regular Expressions with the regexp Package\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-regular-expressions-regexp-featured.png\",\"datePublished\":\"2026-04-28T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:58+00:00\",\"description\":\"Learn Go regular expressions with simple examples: match, find and replace text, use capture groups and avoid the common RE2 syntax errors.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-regular-expressions-regexp-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-regular-expressions-regexp-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Regular Expressions featured image: cards for finding numbers, capture groups and replacing text\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-regular-expressions-regexp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Regular Expressions with the regexp Package\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Regular Expressions with the regexp Package","description":"Learn Go regular expressions with simple examples: match, find and replace text, use capture groups and avoid the common RE2 syntax errors.","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:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/","og_locale":"en_US","og_type":"article","og_title":"Go Regular Expressions with the regexp Package","og_description":"Learn Go regular expressions with simple examples: match, find and replace text, use capture groups and avoid the common RE2 syntax errors.","og_url":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-28T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:58+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Regular Expressions with the regexp Package","datePublished":"2026-04-28T03:30:00+00:00","dateModified":"2026-10-10T15:50:58+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/"},"wordCount":670,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-featured.png","keywords":["Go Lang","Go Regex","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/","url":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/","name":"Go Regular Expressions with the regexp Package","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-featured.png","datePublished":"2026-04-28T03:30:00+00:00","dateModified":"2026-10-10T15:50:58+00:00","description":"Learn Go regular expressions with simple examples: match, find and replace text, use capture groups and avoid the common RE2 syntax errors.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-regular-expressions-regexp-featured.png","width":2400,"height":1260,"caption":"Go Regular Expressions featured image: cards for finding numbers, capture groups and replacing text"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-regular-expressions-regexp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Regular Expressions with the regexp Package"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":314,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions\/314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/268"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=289"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}