{"id":19429,"date":"2020-07-13T05:43:11","date_gmt":"2020-07-13T12:43:11","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19429"},"modified":"2022-07-20T08:33:36","modified_gmt":"2022-07-20T15:33:36","slug":"ruby-regex","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/ruby-regex\/","title":{"rendered":"Using Regular Expressions (RegEx) in Ruby"},"content":{"rendered":"\n<p>You may have heard of RegEx, which is short for regular expressions. It can come off as intimidating, but it\u2019s not too bad once you get used to what the patterns mean and how to construct an actual expression and use it. Once you get used to thinking about strings and text in a more abstract way, it can be a useful tool for solving problems where you are looking for common patterns in a set of data.&nbsp;<br><\/p>\n\n\n\n<p>RegEx is a method of pattern matching: a way to filter strings or text based on a pattern, usually to extract and modify the desired text. In this article, we will discuss how to use Regular Expressions and how to test those expressions using Ruby methods to incorporate into your logic for your project.<br><\/p>\n\n\n\n<p>One tool that is extremely helpful when it comes to visualizing and understanding RegEx is a site called <a href=\"https:\/\/rubular.com\/r\/GUtDmZfetTUXXl\" target=\"_blank\" rel=\"noopener\" rel=\"nofollow\">Rubular<\/a>. Click the link here to test RegEx using the block of text that\u2019s already been populated. You\u2019ll notice that in between the two forward slashes is a string with the word \u2018neighbor\u2019 in it.&nbsp;<br><\/p>\n\n\n\n<p>Believe it or not, this is a regular expression! Whole words, sentences, paragraphs even can technically be called regular expressions (as long as they are in between two forward slashes). The Rubular environment highlights for us every single instance of the pattern \u2018neighbor\u2019 in our block of text \u2013 even instances where neighbor is part of a bigger word, too! That being said, you might want to find something more abstract than an exact word match. This is where metacharacters come in.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Metacharacters<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"631\" src=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/anas-alshanti-feXpdV001o4-unsplash.jpg\" alt=\"\" class=\"wp-image-19430\" srcset=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/anas-alshanti-feXpdV001o4-unsplash.jpg 1000w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/anas-alshanti-feXpdV001o4-unsplash-768x485.jpg 768w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/anas-alshanti-feXpdV001o4-unsplash-770x486.jpg 770w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/anas-alshanti-feXpdV001o4-unsplash-20x13.jpg 20w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/anas-alshanti-feXpdV001o4-unsplash-385x243.jpg 385w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption>Using RegEx can be challenging for seasoned programmers, so don\u2019t get discouraged.<\/figcaption><\/figure>\n\n\n\n<p>Just as atoms are the building blocks of pretty much everything we see around, metacharacters are the building blocks of regular expressions. As you add on to your regular expression, the overall pattern changes. And when the overall pattern changes, the results you get back from from the methods you use can be different.&nbsp;<br><\/p>\n\n\n\n<p>Listed below are several ways to modify your regular expression so you can find a pattern that works for you. There is no one absolutely <em>right<\/em> way to write a regular expression for phone numbers or emails, etc. \u2013 it\u2019s all about what your needs are for your project.&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>Metacharacter<\/td><td>Matches<\/td><td>Example<\/td><\/tr><tr><td>[abc]<\/td><td>A character class that matches a single character in the string that could be a, b or c<br><\/td><td>\/[eig]\/ can match portions of neighbor, apple, or gate<\/td><\/tr><tr><td>[^abc]\t<\/td><td>A negated character class that matches every single character in the string <strong><em>but<\/em><\/strong> a, b or c<\/td><td>\/[^eig]\/ can match portions of neighbor, apple, or gate<\/td><\/tr><tr><td>[a-z]\t<\/td><td>A character class that matches any single character in the range a-z<\/td><td>\/[e-i]\/ can match single characters in portions of neighbor, apple, or gate<br><\/td><\/tr><tr><td>[a-zA-Z]<\/td><td>A character class that matches a range of characters from a-z or A-Z<br><\/td><td>\/[e-i]\/ can match single characters in portions of \u201cHi neighbor!\u201d, Grapple, or gate<\/td><\/tr><tr><td>^\t<\/td><td>Start of line<\/td><td>\/^Hello\/ matches lines that start with \u2018Hello\u2019<\/td><\/tr><tr><td>$<\/td><td>End of line<\/td><td>\/Goodbye$\/ matches lines that end in \u2018Goodbye\u2019<\/td><\/tr><tr><td>\\A<\/td><td>Start of string. Similar to \u2018^\u2019 , but with no multiline mode<\/td><td>\/\\Aa\/ matches the \u2018a\u2019 in apple, but not the \u2018a\u2019 in apricot since it\u2019s not the beginning of the string:<br>apple<br>apricot<\/td><\/tr><tr><td>\\z\t<\/td><td>End of string. Similar to \u2018$\u2019, but with no multiline mode<\/td><td>\/\\za\/ matches the \u2018a\u2019 in zebra, but not the \u2018a\u2019 in libra since it\u2019s not the end of the string<br>librazebra<\/td><\/tr><tr><td>.<\/td><td>Wild card. Dot matches any character.&nbsp;<\/td><td>\/.\/ will match any single character in apple<\/td><\/tr><tr><td>+<\/td><td>Matches one or more of the previous metacharacter<\/td><td>\/aa+\/ will match \u2018aa\u2019, \u2018aaaaaaa\u2019 but will not match \u2018a\u2019 since it has to be one or more of the previous metacharacter (which in this instance is the second a)<\/td><\/tr><tr><td>*<\/td><td>Matches zero or more of the previous metacharacter<\/td><td>\/ab*\/ will match \u2018a\u2019, \u2018ab\u2019, \u2018abbbbbb\u2019<\/td><\/tr><tr><td>\\s<\/td><td>Any whitespace character<\/td><td>\/^The\\s.+s$\/ will match <em>The Beatles<\/em>, <em>The Rolling Stones, The Cranberries, etc.<\/em><\/td><\/tr><tr><td>\\S<\/td><td>Any non-whitespace character<\/td><td>\/\\S+\/ will match <em>The Beatles<\/em>, <em>The Rolling Stones, The Cranberries, etc.<\/em><\/td><\/tr><tr><td>\\d<\/td><td>Any digit<\/td><td>\/\\d+\/ will match 22, 33333, 0, etc<\/td><\/tr><tr><td>\\D<\/td><td>Any non-digit<\/td><td>\/\\D+\/ will match \u2018Hello, goodbye\u2019<\/td><\/tr><tr><td>\\w<\/td><td>Any word character<\/td><td>\/ny\\w*\/ will match \u2018ny_152\u2019, \u2018nypost39\u2019, etc<\/td><\/tr><tr><td>\\W<\/td><td>Any non-word character<\/td><td>\/\\W+\/ will match \u2018)(*&amp;^%$\u2019<\/td><\/tr><tr><td>a{3}<\/td><td>Exactly 3 of \u2018a\u2019<\/td><td>\/\\d{3}-\\d{3}-\\d{4}\/ will match 555-555-5555<\/td><\/tr><tr><td>a{3,}<\/td><td>Three or more of \u2018a\u2019<\/td><td>\/[a-zA-Z0-9!#$^&amp;*)(]{8,}\/ will match \u2018xE*BqRx14B7TAQp\u2019 \u21d0 which looks like it could be used as a password!<\/td><\/tr><tr><td>a{3, 6}<\/td><td>Three to six of \u2018a\u2019<\/td><td>\/[a-zA-Z0-9!#$^&amp;*)(]{8,32}\/ will match \u20180XX!pC3Odpu30Qc\u2019 because it\u2019s more than 3 and less than 32 characters in length<\/td><\/tr><tr><td>a?<\/td><td>0 or 1 of \u2018a\u2019<\/td><td>\/\\d?-\\d{3)-\\d{3}-\\d{4}\/ will match a phone number with an international code attached to front and one without an international code attached to front.&nbsp;<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p><\/p>\n\n\n\n<p>Using metacharacters is great for validation when it comes to users filling out forms on websites. We want to make sure correct information is entered \u2013 that would be a great use of RegEx to make sure the pattern of an address or of an email or phone number is the correct format. This leads to better organized databases with less user error when registering new accounts.&nbsp;<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods to Test RegEx in Ruby<\/h2>\n\n\n\n<p>Here\u2019s the code we are going to use to differentiate between scan and match:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#!\/usr\/bin\/ruby\n \nclass RegexTest\n   def initialize(str, regex)\n      @str = str\n      @regex = regex\n      @result = str.scan(regex)\n   end\n   def display_details()\n      puts &quot;String =  #@str&quot;\n      puts &quot;regex =  #@regex&quot;\n      puts &quot;result = #@result&quot;\n   end\nend\n# Create Objects\nstr1 = RegexTest.new(&quot;The rain in Spain stays mainly on the plain&quot;, \/\\w+ain\/)\nstr2 = RegexTest.new(&quot;In Hertford, Hereford, and Hampshire, hurricanes hardly ever happen&quot;, \/H\\w+\/)\n# Call Methods\nstr1.display_details()\nstr2.display_details()\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Scan<\/p>\n\n\n\n<p>The scan method in Ruby returns an array of all strings that match your regular expression:<br><\/p>\n\n\n\n<p>str1: &nbsp;<code>result = [\"rain\", \"Spain\", \"main\", \"plain\"]<\/code><\/p>\n\n\n\n<p>str2: &nbsp;<code>result = [\"Hertford\", \"Hereford\", \"Hampshire\"]<\/code><br><\/p>\n\n\n\n<p>This allows you to do whatever you would like with the result.<br><\/p>\n\n\n\n<p>RegExp Match<\/p>\n\n\n\n<p>The regular expression Match method is very, VERY similar to scan, but finds the first instance of a match instead of all matches. Change @result = str.scan(regex) to&nbsp; @result = str.match(regex) to take a look at the difference:&nbsp;<br><\/p>\n\n\n\n<p>str1: <code>result = rain<\/code><\/p>\n\n\n\n<p>str2: <code>result = Hertford<\/code><br><\/p>\n\n\n\n<p>Match, however, returns a &lt;Matchdata&gt; object. It\u2019s got some methods associated with it that can be used in your logic when you use your results. Take a look at the <a href=\"https:\/\/ruby-doc.org\/core-2.4.0\/MatchData.html\" target=\"_blank\" rel=\"noopener\" rel=\"nofollow\">Ruby<\/a> docs for more information on what you could use there.&nbsp;<br><\/p>\n\n\n\n<p>Grep<\/p>\n\n\n\n<p>Grep is an enumerable method for finding matching strings in arrays. It will return an array of all strings that match your regular expression. With the code we have, we have to make sure that the string we passed in is split up into an array.&nbsp;<br><\/p>\n\n\n\n<p>To do this change this line of code:<\/p>\n\n\n\n<p><code>@result = str.match(regex)<\/code><\/p>\n\n\n\n<p>And change it to:<\/p>\n\n\n\n<p><code>@result = str.split(\/\\s|,\/).grep(regex);<br><\/code><\/p>\n\n\n\n<p>You will then get a result similar to the first result:&nbsp;<br><\/p>\n\n\n\n<p>str1: &nbsp;<code>result = [\"rain\", \"Spain\", \"main\", \"plain\"]<\/code><\/p>\n\n\n\n<p>str2: &nbsp;<code>result = [\"Hertford\", \"Hereford\", \"Hampshire\"]<\/code><br><\/p>\n\n\n\n<p>Str =~ RegEx<\/p>\n\n\n\n<p>Using the <strong>=~<\/strong> basic matching operator, we can compare the string to the regular expression and return the first index of a match. It will return nil if there is no match.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this article, we discussed how to use regular expressions (RegEx) in Ruby. If you want to learn more about what you can build with Ruby, check out our article, \u201d<a href=\"https:\/\/careerkarma.com\/blog\/what-is-ruby-used-for\/\"><strong>What Is Ruby Code Used For?<\/strong><\/a>\u201d<br><\/p>\n\n\n\n<p><strong>Want a better way to learn Ruby? Let Career Karma help you find the best training program for you.<\/strong><br><\/p>\n","protected":false},"excerpt":{"rendered":"You may have heard of RegEx, which is short for regular expressions. It can come off as intimidating, but it\u2019s not too bad once you get used to what the patterns mean and how to construct an actual expression and use it. Once you get used to thinking about strings and text in a more&hellip;","protected":false},"author":77,"featured_media":18530,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17278],"tags":[],"class_list":{"0":"post-19429","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ruby"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Ruby","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Using Regular Expressions (RegEx) in Ruby | Career Karma<\/title>\n<meta name=\"description\" content=\"Writing RegEx is challenging, but we\u2019ve got you covered with this review of metacharacters and Ruby methods to use with your Regular Expressions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Regular Expressions (RegEx) in Ruby\" \/>\n<meta property=\"og:description\" content=\"Writing RegEx is challenging, but we\u2019ve got you covered with this review of metacharacters and Ruby methods to use with your Regular Expressions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-13T12:43:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-20T15:33:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"718\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"Using Regular Expressions (RegEx) in Ruby\",\"datePublished\":\"2020-07-13T12:43:11+00:00\",\"dateModified\":\"2022-07-20T15:33:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\"},\"wordCount\":1198,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg\",\"articleSection\":[\"Ruby\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\",\"name\":\"Using Regular Expressions (RegEx) in Ruby | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg\",\"datePublished\":\"2020-07-13T12:43:11+00:00\",\"dateModified\":\"2022-07-20T15:33:36+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"Writing RegEx is challenging, but we\u2019ve got you covered with this review of metacharacters and Ruby methods to use with your Regular Expressions.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/ruby-regex\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg\",\"width\":1020,\"height\":718},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-regex\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ruby\",\"item\":\"https:\/\/careerkarma.com\/blog\/ruby\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using Regular Expressions (RegEx) in Ruby\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\/\/www.linkedin.com\/in\/cmvnk\"],\"url\":\"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Regular Expressions (RegEx) in Ruby | Career Karma","description":"Writing RegEx is challenging, but we\u2019ve got you covered with this review of metacharacters and Ruby methods to use with your Regular Expressions.","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:\/\/careerkarma.com\/blog\/ruby-regex\/","og_locale":"en_US","og_type":"article","og_title":"Using Regular Expressions (RegEx) in Ruby","og_description":"Writing RegEx is challenging, but we\u2019ve got you covered with this review of metacharacters and Ruby methods to use with your Regular Expressions.","og_url":"https:\/\/careerkarma.com\/blog\/ruby-regex\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-13T12:43:11+00:00","article_modified_time":"2022-07-20T15:33:36+00:00","og_image":[{"width":1020,"height":718,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"Using Regular Expressions (RegEx) in Ruby","datePublished":"2020-07-13T12:43:11+00:00","dateModified":"2022-07-20T15:33:36+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/"},"wordCount":1198,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg","articleSection":["Ruby"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/ruby-regex\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/","url":"https:\/\/careerkarma.com\/blog\/ruby-regex\/","name":"Using Regular Expressions (RegEx) in Ruby | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg","datePublished":"2020-07-13T12:43:11+00:00","dateModified":"2022-07-20T15:33:36+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"Writing RegEx is challenging, but we\u2019ve got you covered with this review of metacharacters and Ruby methods to use with your Regular Expressions.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/ruby-regex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dC6Pb2JdAqs-unsplash.jpg","width":1020,"height":718},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/ruby-regex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Ruby","item":"https:\/\/careerkarma.com\/blog\/ruby\/"},{"@type":"ListItem","position":3,"name":"Using Regular Expressions (RegEx) in Ruby"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19429"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18530"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}