{"id":256573,"date":"2024-05-23T01:07:42","date_gmt":"2024-05-23T01:07:42","guid":{"rendered":"https:\/\/namso-gen.co\/blog\/?p=256573"},"modified":"2024-05-23T01:07:42","modified_gmt":"2024-05-23T01:07:42","slug":"how-to-capture-matched-value-with-regex-in-ruby","status":"publish","type":"post","link":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/","title":{"rendered":"How to capture matched value with regex in Ruby?"},"content":{"rendered":"<p>Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and manipulate text based on specific patterns. One common task in regex is capturing matched values, which means extracting specific parts of a string that match a given pattern. In this article, we will explore how to capture matched values with regex in Ruby.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#The_Basics_of_Regular_Expressions\" title=\"The Basics of Regular Expressions\">The Basics of Regular Expressions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#Capturing_Matched_Values_in_Ruby\" title=\"Capturing Matched Values in Ruby\">Capturing Matched Values in Ruby<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#FAQs_about_Capturing_Matched_Values\" title=\"FAQs about Capturing Matched Values\">FAQs about Capturing Matched Values<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#1_How_do_I_capture_a_specific_part_of_a_string_with_regex\" title=\"1. How do I capture a specific part of a string with regex?\">1. How do I capture a specific part of a string with regex?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#2_Can_I_capture_multiple_parts_of_a_string_with_a_single_regex_pattern\" title=\"2. Can I capture multiple parts of a string with a single regex pattern?\">2. Can I capture multiple parts of a string with a single regex pattern?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#3_What_if_my_regex_pattern_doesnt_have_any_capturing_groups\" title=\"3. What if my regex pattern doesn&#8217;t have any capturing groups?\">3. What if my regex pattern doesn&#8217;t have any capturing groups?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#4_How_do_I_capture_a_number_with_decimal_places_using_regex\" title=\"4. How do I capture a number with decimal places using regex?\">4. How do I capture a number with decimal places using regex?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#5_Is_the_order_of_captured_values_guaranteed\" title=\"5. Is the order of captured values guaranteed?\">5. Is the order of captured values guaranteed?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#6_Can_I_capture_nested_values_with_regex\" title=\"6. Can I capture nested values with regex?\">6. Can I capture nested values with regex?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#7_What_if_my_regex_pattern_matches_multiple_occurrences_of_the_same_group\" title=\"7. What if my regex pattern matches multiple occurrences of the same group?\">7. What if my regex pattern matches multiple occurrences of the same group?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#8_How_do_I_capture_a_word_with_optional_characters_before_and_after\" title=\"8. How do I capture a word with optional characters before and after?\">8. How do I capture a word with optional characters before and after?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#9_Can_I_modify_the_captured_values_directly_in_the_match_object\" title=\"9. Can I modify the captured values directly in the match object?\">9. Can I modify the captured values directly in the match object?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#10_How_do_I_capture_a_string_that_spans_across_multiple_lines\" title=\"10. How do I capture a string that spans across multiple lines?\">10. How do I capture a string that spans across multiple lines?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#11_Can_I_capture_matched_values_case-insensitively\" title=\"11. Can I capture matched values case-insensitively?\">11. Can I capture matched values case-insensitively?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#12_How_do_I_capture_non-overlapping_values_in_a_repeated_pattern\" title=\"12. How do I capture non-overlapping values in a repeated pattern?\">12. How do I capture non-overlapping values in a repeated pattern?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"The_Basics_of_Regular_Expressions\"><\/span>The Basics of Regular Expressions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before we dive into capturing matched values, let&#8217;s review the basics of regular expressions:<\/p>\n<p>1. <b>What is a regular expression?<\/b><br \/>\nA regular expression is a sequence of characters that form a search pattern. It can be used to find, match, and manipulate text based on specific rules and patterns.<\/p>\n<p>2. <b>Why use regular expressions?<\/b><br \/>\nRegular expressions are incredibly versatile and useful in various scenarios, such as data validation, text parsing, and pattern matching. They provide a concise and powerful way to work with textual data.<\/p>\n<p>3. <b>How do regular expressions work in Ruby?<\/b><br \/>\nRuby has built-in support for regular expressions through the Regex class. You can create a regular expression by simply enclosing your pattern between two forward slashes, like this: `\/pattern\/`.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Capturing_Matched_Values_in_Ruby\"><\/span>Capturing Matched Values in Ruby<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Capturing matched values with regex in Ruby is relatively straightforward. When a pattern match occurs, Ruby provides a way to store specific parts of the matched string into variables. These captured values can then be accessed and used in your program. Here&#8217;s how to do it:<\/p>\n<p><b>Step 1:<\/b> Define a regular expression pattern that includes capturing groups.<br \/>\n<b>Step 2:<\/b> Use the `match` method on a string, passing in the regex pattern as an argument.<br \/>\n<b>Step 3:<\/b> Access the captured values using the `captures` method on the resulting match object.<\/p>\n<p>Let&#8217;s look at an example. Suppose we have a string that contains a name and an age in the format &#8220;John, 25&#8221;. We want to extract both the name and the age using regex.<\/p>\n<p>&#8220;`ruby<br \/>\nstring = &#8220;John, 25&#8221;<br \/>\nregex = \/(w+), (d+)\/<br \/>\nmatch = regex.match(string)<br \/>\nname = match.captures[0]<br \/>\nage = match.captures[1]<br \/>\nputs &#8220;Name: #{name}, Age: #{age}&#8221;<br \/>\n&#8220;`<\/p>\n<p>In this example, we define a regex pattern with two capturing groups: `(w+)` for the name and `(d+)` for the age. We then call the `match` method on the string and assign the result to the `match` variable. Finally, we extract the captured values using the `captures` method and assign them to the `name` and `age` variables.<\/p>\n<p><b>The answer to the question &#8220;How to capture matched value with regex in Ruby?&#8221; is:<\/b> You can capture matched values with regex in Ruby by using capturing groups in your pattern and accessing the captured values through the `captures` method on the resulting match object.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"FAQs_about_Capturing_Matched_Values\"><\/span>FAQs about Capturing Matched Values<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"1_How_do_I_capture_a_specific_part_of_a_string_with_regex\"><\/span>1. How do I capture a specific part of a string with regex?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nTo capture a specific part of a string, you need to enclose that part in parentheses within your regex pattern. The captured value can then be accessed using the `captures` method.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Can_I_capture_multiple_parts_of_a_string_with_a_single_regex_pattern\"><\/span>2. Can I capture multiple parts of a string with a single regex pattern?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can capture multiple parts of a string by using multiple capturing groups in your regex pattern. Each captured value will be accessible through the `captures` method, indexed in the order they appear.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_What_if_my_regex_pattern_doesnt_have_any_capturing_groups\"><\/span>3. What if my regex pattern doesn&#8217;t have any capturing groups?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nIf your regex pattern doesn&#8217;t have any capturing groups, the `captures` method will return an empty array. However, you can still match and extract the entire matched string using the `to_s` method on the match object.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_How_do_I_capture_a_number_with_decimal_places_using_regex\"><\/span>4. How do I capture a number with decimal places using regex?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nTo capture a number with decimal places, you can use a capturing group with the pattern `d+(.d+)?`. This pattern matches one or more digits followed by an optional group of a dot and one or more digits.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_Is_the_order_of_captured_values_guaranteed\"><\/span>5. Is the order of captured values guaranteed?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, the order of captured values corresponds to the order of the capturing groups in your regex pattern. The `captures` method returns an array where each element represents a captured value in the order they appear.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_Can_I_capture_nested_values_with_regex\"><\/span>6. Can I capture nested values with regex?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can capture nested values in Ruby using nested capturing groups in your regex pattern. The captured values will be accessible in the nested order through the `captures` method.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"7_What_if_my_regex_pattern_matches_multiple_occurrences_of_the_same_group\"><\/span>7. What if my regex pattern matches multiple occurrences of the same group?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nIf your regex pattern matches multiple occurrences of the same capturing group, the `captures` method will return an array of captured values, only containing the last matched occurrence for each capturing group.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8_How_do_I_capture_a_word_with_optional_characters_before_and_after\"><\/span>8. How do I capture a word with optional characters before and after?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nTo capture a word with optional characters before and after, you can use capturing groups to isolate the desired part. For example, `(before_word)?(word)(after_word)?` captures the &#8220;word&#8221; while also allowing for the optional &#8220;before_word&#8221; and &#8220;after_word&#8221;.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"9_Can_I_modify_the_captured_values_directly_in_the_match_object\"><\/span>9. Can I modify the captured values directly in the match object?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nNo, the captured values returned by the `captures` method are read-only and cannot be modified. If you need to manipulate the captured values, you should assign them to new variables and work with those instead.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"10_How_do_I_capture_a_string_that_spans_across_multiple_lines\"><\/span>10. How do I capture a string that spans across multiple lines?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nTo capture a string that spans across multiple lines, you can use the `m` flag after the regex pattern, like this: `\/pattern\/m`. This flag enables the &#8220;multiline mode&#8221; in Ruby, allowing the dot character to match newline characters as well.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"11_Can_I_capture_matched_values_case-insensitively\"><\/span>11. Can I capture matched values case-insensitively?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nYes, you can use the `i` flag after the regex pattern, like this: `\/pattern\/i`. This flag enables case-insensitive matching, meaning the regex will match both uppercase and lowercase characters.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"12_How_do_I_capture_non-overlapping_values_in_a_repeated_pattern\"><\/span>12. How do I capture non-overlapping values in a repeated pattern?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\nBy default, regex patterns capture the last matched occurrence of a repeated group. If you want to capture non-overlapping values in a repeated pattern, you can use a positive lookahead assertion `(?=pattern)` to ensure that each match is followed by the given pattern, without consuming it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and manipulate text based on specific patterns. One common task in regex is capturing matched values, which means extracting specific parts of a string that match a given pattern. In this &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to capture matched value with regex in Ruby?\" class=\"read-more button\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#more-256573\">Read more<span class=\"screen-reader-text\">How to capture matched value with regex in Ruby?<\/span><\/a><\/p>\n","protected":false},"author":65,"featured_media":107420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86279],"tags":[],"class_list":["post-256573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to capture matched value with regex in Ruby?<\/title>\n<meta name=\"description\" content=\"Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to capture matched value with regex in Ruby?\" \/>\n<meta property=\"og:description\" content=\"Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and\" \/>\n<meta property=\"og:url\" content=\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\" \/>\n<meta property=\"og:site_name\" content=\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/synchronyfinancial\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-23T01:07:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Timothy Mathis\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@synchrony\" \/>\n<meta name=\"twitter:site\" content=\"@synchrony\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Timothy Mathis\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\"},\"author\":{\"name\":\"Timothy Mathis\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318\"},\"headline\":\"How to capture matched value with regex in Ruby?\",\"datePublished\":\"2024-05-23T01:07:42+00:00\",\"dateModified\":\"2024-05-23T01:07:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\"},\"wordCount\":1006,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"articleSection\":[\"Learn\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\",\"name\":\"How to capture matched value with regex in Ruby?\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\"},\"datePublished\":\"2024-05-23T01:07:42+00:00\",\"dateModified\":\"2024-05-23T01:07:42+00:00\",\"description\":\"Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and\",\"breadcrumb\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/namso-gen.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to capture matched value with regex in Ruby?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"description\":\"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co\",\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/namso-gen.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"contentUrl\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"width\":500,\"height\":164,\"caption\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\"},\"image\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/synchronyfinancial\",\"https:\/\/twitter.com\/synchrony\",\"https:\/\/www.youtube.com\/synchronyfinancial\",\"https:\/\/www.instagram.com\/synchrony\",\"https:\/\/www.linkedin.com\/company\/synchrony-financial\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318\",\"name\":\"Timothy Mathis\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Timothy Mathis\"},\"description\":\"Guest author Timothy Mathis has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to capture matched value with regex in Ruby?","description":"Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and","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:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/","og_locale":"en_US","og_type":"article","og_title":"How to capture matched value with regex in Ruby?","og_description":"Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and","og_url":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/","og_site_name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","article_publisher":"https:\/\/www.facebook.com\/synchronyfinancial","article_published_time":"2024-05-23T01:07:42+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2024\/03\/faq.png","type":"image\/png"}],"author":"Timothy Mathis","twitter_card":"summary_large_image","twitter_creator":"@synchrony","twitter_site":"@synchrony","twitter_misc":{"Written by":"Timothy Mathis","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#article","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/"},"author":{"name":"Timothy Mathis","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318"},"headline":"How to capture matched value with regex in Ruby?","datePublished":"2024-05-23T01:07:42+00:00","dateModified":"2024-05-23T01:07:42+00:00","mainEntityOfPage":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/"},"wordCount":1006,"commentCount":0,"publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"articleSection":["Learn"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/","url":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/","name":"How to capture matched value with regex in Ruby?","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/#website"},"datePublished":"2024-05-23T01:07:42+00:00","dateModified":"2024-05-23T01:07:42+00:00","description":"Regex, short for regular expression, is a powerful tool for pattern matching in programming languages such as Ruby. It allows you to search for and","breadcrumb":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/namso-gen.co\/blog\/how-to-capture-matched-value-with-regex-in-ruby\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/namso-gen.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to capture matched value with regex in Ruby?"}]},{"@type":"WebSite","@id":"https:\/\/namso-gen.co\/blog\/#website","url":"https:\/\/namso-gen.co\/blog\/","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","description":"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co","publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/namso-gen.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/namso-gen.co\/blog\/#organization","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","url":"https:\/\/namso-gen.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","contentUrl":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","width":500,"height":164,"caption":"Namso Gen Blog - Free Credit Card Generator [100% Valid]"},"image":{"@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/synchronyfinancial","https:\/\/twitter.com\/synchrony","https:\/\/www.youtube.com\/synchronyfinancial","https:\/\/www.instagram.com\/synchrony","https:\/\/www.linkedin.com\/company\/synchrony-financial"]},{"@type":"Person","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/ffa5be155490b2344e28f672fcc1e318","name":"Timothy Mathis","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Timothy Mathis"},"description":"Guest author Timothy Mathis has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here."}]}},"_links":{"self":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/256573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/comments?post=256573"}],"version-history":[{"count":0,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/256573\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media\/107420"}],"wp:attachment":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media?parent=256573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/categories?post=256573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/tags?post=256573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}