<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: pattern code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 02:01:30 GMT</pubDate>
    <description>DZone Snippets: pattern code</description>
    <item>
      <title>Finding your match with Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5157</link>
      <description>This example finds an email subject in a string and passes the value to a variable called 'subject'.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;subject = (/^Subject\: (.+)$/).match(email)[1]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Prior to this code I would have used the following:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  email[/^Subject\: (.+)$/]&lt;br /&gt;  subject = $1&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Reference: &lt;a href="http://snippets.dzone.com/posts/show/5152"&gt;Ruby SMTP Server - Save to Database&lt;/a&gt; [dzone.com]</description>
      <pubDate>Wed, 20 Feb 2008 09:20:51 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5157</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Lookaround in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5108</link>
      <description>What follows below is the output from an irb session to specifically try out Lookahead and Lookbehind in regex.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):002:0&gt; "question"[/q(?=u)/]&lt;br /&gt;=&gt; "q"&lt;br /&gt;irb(main):003:0&gt; "qu&gt;"[/qu(?=&gt;)/]&lt;br /&gt;=&gt; "qu"&lt;br /&gt;irb(main):004:0&gt; "qu"[/qu(?=&gt;)/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):006:0&gt; "accumulator"[/(?=c)cumulator/]&lt;br /&gt;=&gt; "cumulator"&lt;br /&gt;irb(main):007:0&gt; "accumulator"[/a(?=c)cumulator/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):009:0&gt; "abc"[/abc(?=c)/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):010:0&gt; "abc"[/ab(?=c)/]&lt;br /&gt;=&gt; "ab"&lt;br /&gt;&lt;br /&gt;irb(main):011:0&gt; "abd"[/ab(?!c)/]&lt;br /&gt;=&gt; "ab"&lt;br /&gt;irb(main):012:0&gt; "abc"[/ab(?!c)/]&lt;br /&gt;=&gt; nil&lt;br /&gt;&lt;br /&gt;irb(main):013:0&gt; "abc"[/a(?&lt;=b)c/] # lookbehind doesn't work in Ruby&lt;br /&gt;SyntaxError: compile error&lt;br /&gt;(irb):13: undefined (?...) sequence: /a(?&lt;=b)c/&lt;br /&gt;        from (irb):13&lt;br /&gt;        from :0&lt;br /&gt;irb(main):014:0&gt; "abc"[/(?&lt;=a)bc/] # lookbehind doesn't work in Ruby&lt;br /&gt;SyntaxError: compile error&lt;br /&gt;(irb):14: undefined (?...) sequence: /(?&lt;=a)bc/&lt;br /&gt;        from (irb):14&lt;br /&gt;        from :0&lt;br /&gt;&lt;br /&gt;irb(main):022:0&gt; "how's the weather?"[/how.*(?=the)/]&lt;br /&gt;=&gt; "how's the wea"&lt;br /&gt;irb(main):024:0&gt; "how's the weather?"[/how.*(?=[the])/]&lt;br /&gt;=&gt; "how's the weath"&lt;br /&gt;irb(main):025:0&gt; "how's the weather?"[/how.*(?=t)/]&lt;br /&gt;=&gt; "how's the wea"&lt;br /&gt;irb(main):037:0&gt; "how's the weather?"[/how.+(?=\bt)/]&lt;br /&gt;=&gt; "how's "&lt;br /&gt;&lt;br /&gt;irb(main):057:0&gt; "how's the weather?"[/ho.*(?=[a-z])/]&lt;br /&gt;=&gt; "how's the weathe"&lt;br /&gt;irb(main):061:0&gt; "how's the weather?"[/ho.*(?=['])/]&lt;br /&gt;=&gt; "how"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;reference: &lt;a href="http://www.regular-expressions.info/quickstart.html"&gt;Regular Expressions Quick Start&lt;/a&gt; [regular-expressions.info]</description>
      <pubDate>Tue, 05 Feb 2008 16:56:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5108</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Greedy vs Lazy in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5103</link>
      <description>The greedy expression can be seen as a True *and* False predicate, meaning true while the token is valid, while being false if the pattern matching hasn't been exhausted. &lt;br /&gt;The lazy expression is the True *or* False predicate, meaning true while the token is valid, or false if the pattern match hasn't been fully exhausted.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):037:0&gt; "&lt;EM&gt;first&lt;/EM&gt;"[/&lt;.+&gt;/] #greedy &lt;br /&gt;=&gt; "&lt;EM&gt;first&lt;/EM&gt;"&lt;br /&gt;irb(main):038:0&gt; "&lt;EM&gt;first&lt;/EM&gt;"[/&lt;.+?&gt;/] #lazy&lt;br /&gt;=&gt; "&lt;EM&gt;"&lt;br /&gt;irb(main):039:0&gt; "&lt;EM&gt;first&lt;/EM&gt;"[/&lt;[^&lt;&gt;]+&gt;/] # better solution&lt;br /&gt;=&gt; "&lt;EM&gt;"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;source: &lt;a href="http://www.regular-expressions.info/quickstart.html"&gt;Regular Expression Quick Start&lt;/a&gt; [regular-expressions.info]</description>
      <pubDate>Mon, 04 Feb 2008 13:09:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5103</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Backreferences in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5096</link>
      <description>This irb session example shows back referencing, where a token enclosed within round brackets is automatically assigned as a variable. That variable is represented by a dollar ($) symbol followed by it's index number starting at 1.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#match capture = STRONG&lt;br /&gt;irb(main):652:0&gt; "&lt;STRONG&gt;text here&lt;/STRONG&gt;"[/&lt;(.*)&gt;.*&lt;\/\1&gt;/]&lt;br /&gt;=&gt; "&lt;STRONG&gt;text here&lt;/STRONG&gt;"&lt;br /&gt;&lt;br /&gt;irb(main):655:0&gt; "abttba"[/^(.)(.).*\2\1$/]&lt;br /&gt;=&gt; "abttba"&lt;br /&gt;irb(main):658:0&gt; "ab123ttba"[/^(.)(.)(123).*\2\1\3$/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):659:0&gt; "ab123ttba123"[/^(.)(.)(123).*\2\1\3$/]&lt;br /&gt;=&gt; "ab123ttba123"&lt;br /&gt;irb(main):663:0&gt; "how are you"[/(o)*\1/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):664:0&gt; "how are you"[/(o).*\1/]&lt;br /&gt;=&gt; "ow are yo"&lt;br /&gt;irb(main):685:0&gt; "how are you"[/(o)[^\1]+\1/]&lt;br /&gt;=&gt; "ow are yo"&lt;br /&gt;irb(main):686:0&gt; "how are you"[/(o)[^\1]+\1u/]&lt;br /&gt;=&gt; "ow are you"&lt;br /&gt;irb(main):692:0&gt; "how is Lucy?"[/(o)[^\1]+\1/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):693:0&gt; "how is Lucy?"[/(o)[^\1]+\1?/]&lt;br /&gt;=&gt; "ow is Lucy?"&lt;br /&gt;&lt;br /&gt;irb(main):702:0&gt; "I eat now?".gsub(/(.)\s(\w+)\s(\w+)(.)/,$1)&lt;br /&gt;=&gt; "I"&lt;br /&gt;irb(main):708:0&gt; "I eat now?".gsub(/(.)\s(\w+)\s(\w+)(.)/,"#{$3} #{$2}")&lt;br /&gt;=&gt; "now eat"&lt;br /&gt;irb(main):711:0&gt; "I eat now?".gsub(/(.)\s(\w+)\s(\w+)(.)/,"#{$3} #{$1} #{$2}#{$4}")&lt;br /&gt;=&gt; "now I eat?"&lt;br /&gt;&lt;br /&gt;irb(main):712:0&gt; $1&lt;br /&gt;=&gt; "I"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Backreference support in Ruby uses the following variables:&lt;br /&gt;&lt;br /&gt;     $` returns everything before the matched string.&lt;br /&gt;     $' returns everything after the matched string.&lt;br /&gt;     $+ returns whatever the last bracket match matched.&lt;br /&gt;     $&amp; returns the entire matched string. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):713:0&gt; $&amp;&lt;br /&gt;=&gt; "I eat now?"&lt;br /&gt;&lt;br /&gt;irb(main):715:0&gt; "I eat now? Mother?".gsub(/(.)\s(\w+)\s(\w+)(.)/,"#{$3} #{$1} #{$2}#{$4}")&lt;br /&gt;=&gt; "now I eat? Mother?"&lt;br /&gt;&lt;br /&gt;irb(main):716:0&gt; $'&lt;br /&gt;=&gt; " Mother?"&lt;br /&gt;irb(main):721:0&gt; $'[/M/]&lt;br /&gt;=&gt; "M"&lt;br /&gt;&lt;br /&gt;irb(main):732:0&gt; "I'm hungry ... I eat now? Mother?".gsub(/[^.](.)\s(\w+)\s(\w+)(.)/,"#{$3} #{$1} #{$2}#{$4}")&lt;br /&gt;=&gt; "I'm hungry ...now I eat? Mother?"&lt;br /&gt;irb(main):733:0&gt; $`&lt;br /&gt;=&gt; "I'm hungry ..."&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: These Ruby examples should work from &lt;a href="http://www.rubular.com/"&gt;Rubular&lt;/a&gt; [rubular.com].&lt;br /&gt;Reference: &lt;a href="http://www.webreference.com/js/column5/values.html"&gt;Unix Regular Expressions: Backreferences&lt;/a&gt; [webreference.com]</description>
      <pubDate>Sun, 03 Feb 2008 12:37:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5096</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Repetition in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5089</link>
      <description>This irb session example helps demonstrate repetition in regular expressions using * ? + {}&lt;br /&gt;&lt;br /&gt;Definitions:&lt;br /&gt;&lt;br /&gt;? - the preceding token is optional&lt;br /&gt;+ - find the token 1 or more times&lt;br /&gt;* - find the token 0 or more times&lt;br /&gt;{n} - repeat the token n no of times&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):058:0&gt; "this song is my favourite"[/favou?rite/]&lt;br /&gt;=&gt; "favourite"&lt;br /&gt;irb(main):059:0&gt; "this song is my favorite"[/favou?rite/]&lt;br /&gt;=&gt; "favorite"&lt;br /&gt;&lt;br /&gt;irb(main):100:0&gt; "this is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; "this is"&lt;br /&gt;irb(main):101:0&gt; "this song is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; "this song is"&lt;br /&gt;irb(main):102:0&gt; "this flower is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):103:0&gt; "this video is my favourite\s"[/this\s((song|video)\s)?is/]&lt;br /&gt;=&gt; "this video is"&lt;br /&gt;&lt;br /&gt;irb(main):105:0&gt; "anything you say"[/.*/]&lt;br /&gt;=&gt; "anything you say"&lt;br /&gt;irb(main):119:0&gt; "will be repeated"[/.*/]&lt;br /&gt;=&gt; "will be repeated"&lt;br /&gt;irb(main):116:0&gt; "good times&lt;/p&gt;"[/.*[^&lt;\/p&gt;]/]&lt;br /&gt;=&gt; "good times"&lt;br /&gt;&lt;br /&gt;irb(main):220:0&gt; "test 123 test 123"[/\d+/]&lt;br /&gt;=&gt; "123"&lt;br /&gt;irb(main):224:0&gt; "test 123 test 123"[/\d{2}/]&lt;br /&gt;=&gt; "12"&lt;br /&gt;irb(main):226:0&gt; "test 123 test 123"[/\w+/]&lt;br /&gt;=&gt; "test"&lt;br /&gt;&lt;br /&gt;irb(main):008:0&gt; "try this test that"[/try.\b\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):009:0&gt; "try this test that"[/test.\b\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):233:0&gt; "test 123 test 123"[/\w+\s\d+/]&lt;br /&gt;=&gt; "test 123"&lt;br /&gt;irb(main):248:0&gt; "test 123 test 123"[/\w+\s\d+.*/]&lt;br /&gt;=&gt; "test 123 test 123"&lt;br /&gt;irb(main):249:0&gt; "test this test 123"[/\w+\s\d+.*/]&lt;br /&gt;=&gt; "test 123"&lt;br /&gt;irb(main):250:0&gt; "test this test that"[/\w+\s\d+.*/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):279:0&gt; "try this test that"[/try\s\w[^\s]+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):280:0&gt; "try this test that"[/test\s\w[^\s]+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):310:0&gt; "try this test that"[/test\s\w\B+/]&lt;br /&gt;=&gt; "test tha"&lt;br /&gt;irb(main):308:0&gt; "try this test that"[/try\s\w\B+./]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):309:0&gt; "try this test that"[/test\s\w\B+./]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):322:0&gt; "try this test that"[/try\s\w+\b/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):323:0&gt; "try this test that"[/test\s\w+\b/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):008:0&gt; "try this test that"[/try.\b\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):009:0&gt; "try this test that"[/test.\b\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):010:0&gt; "try this test that"[/test.\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;irb(main):011:0&gt; "try this test that"[/try.\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;&lt;br /&gt;irb(main):012:0&gt; "try this test that"[/try\s\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;irb(main):013:0&gt; "try this test that"[/test\s\w+/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;&lt;br /&gt;irb(main):015:0&gt; "try this test that"[/try\s\w+\s\w+/]&lt;br /&gt;=&gt; "try this test"&lt;br /&gt;&lt;br /&gt;irb(main):041:0&gt; "try this test that"[/\w+\s\w+$/]&lt;br /&gt;=&gt; "test that"&lt;br /&gt;irb(main):043:0&gt; "try this test that"[/^\w+\s\w+/]&lt;br /&gt;=&gt; "try this"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: Similar to CSS the more specific an expression or selector is the less ambiguous it is.</description>
      <pubDate>Sat, 02 Feb 2008 13:56:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5089</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Alternation in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5068</link>
      <description>The following code from an irb session highlights optional pattern matching using an OR operator, represented as a bar (|).&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):003:0&gt; "chickens are sleeping"[/chick|sleeping/]&lt;br /&gt;=&gt; "chick"&lt;br /&gt;irb(main):004:0&gt; "chickens are sleeping"[/sleeping/]&lt;br /&gt;=&gt; "sleeping"&lt;br /&gt;irb(main):005:0&gt; "chickens are sleeping"[/sleeping|chicken/]&lt;br /&gt;=&gt; "chicken"&lt;br /&gt;irb(main):006:0&gt; "chickens are sleeping"[/sleeping|are|chicken/]&lt;br /&gt;=&gt; "chicken"&lt;br /&gt;irb(main):007:0&gt; "chickens are sleeping"[/sleeping|are/]&lt;br /&gt;=&gt; "are"&lt;br /&gt;irb(main):008:0&gt; "chickens are sleeping"[/[^sleeping|are]/]&lt;br /&gt;=&gt; "c"&lt;br /&gt;irb(main):009:0&gt; "chickens are sleeping"[/[^sleeping|are].[a-z]*\s/]&lt;br /&gt;=&gt; "chickens "&lt;br /&gt;irb(main):011:0&gt; "chickens are sleeping"[/[^chickens|are].[a-z]*\s/]&lt;br /&gt;=&gt; " are "&lt;br /&gt;irb(main):015:0&gt; "chickens are sleeping"[/[sleeping|are].[a-z]*\s/]&lt;br /&gt;=&gt; "ickens "&lt;br /&gt;irb(main):020:0&gt; "scared chickens are sleeping"[/are|sleeping/]&lt;br /&gt;=&gt; "are"&lt;br /&gt;irb(main):026:0&gt; "scared chickens are sleeping"[/(are|sleeping)../]&lt;br /&gt;=&gt; "ared "&lt;br /&gt;irb(main):023:0&gt; "scared chickens are sleeping"[/\b(are|sleeping)\b/]&lt;br /&gt;=&gt; "are"&lt;br /&gt;irb(main):025:0&gt; "scared chickens are sleeping"[/\b(are|sleeping)\b.../]&lt;br /&gt;=&gt; "are sl"&lt;br /&gt;irb(main):032:0&gt; "scared chickens are sleeping"[/(monkeys|dancing)|(sheep|laughing)/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):033:0&gt; "scared chickens are sleeping"[/(monkeys|dancing)|(sheep|laughing)|(chickens)/]&lt;br /&gt;=&gt; "chickens"&lt;br /&gt;irb(main):034:0&gt; "scared chickens are sleeping"[/(monkeys|sleeping)|(sheep|laughing)|(chickens)/]&lt;br /&gt;=&gt; "chickens"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 01 Feb 2008 10:19:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5068</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Anchors in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5062</link>
      <description>Anchors are about finding matches beginning with or ending with a certain pattern. &lt;br /&gt;&lt;br /&gt;This example from an irb session helps to show what \b, \w, ^, $ and \B do. \b - matches a word boundary, \w - matches a word character, ^ - matches a character at the beginning of a line, $ - matches the character at the end of a line, and \B matches a word boundary charcter which does not match \w.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):010:0&gt; "paella"[/\ba/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):013:0&gt; "artistic paella wake"[/\wa/]&lt;br /&gt;=&gt; "pa"&lt;br /&gt;irb(main):026:0&gt; "artistic paella wake"[/\B.[a-z]a$/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):027:0&gt; "artistic paella wake"[/\B.[a-z]$/]&lt;br /&gt;=&gt; "ke"&lt;br /&gt;irb(main):039:0&gt; "artistic paella wake"[/\B./]&lt;br /&gt;=&gt; "r"&lt;br /&gt;irb(main):040:0&gt; "artistic paella wake"[/\Ba./]&lt;br /&gt;=&gt; "ae"&lt;br /&gt;irb(main):044:0&gt; "artistic paella wake"[/[^\B.{3}]/]&lt;br /&gt;=&gt; "a"&lt;br /&gt;irb(main):046:0&gt; "artistic paella wake"[/[^\B.]{3}/]&lt;br /&gt;=&gt; "art"&lt;br /&gt;irb(main):047:0&gt; "artistic paella wake"[/[^\w]{3}/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):047:0&gt; "artistic paella wake"[/[^\w]{3}/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):048:0&gt; "artistic paella wake"[/[^\br]{3}/]&lt;br /&gt;=&gt; "tis"&lt;br /&gt;irb(main):050:0&gt; "artistic paella wake"[/[^\b]{3}/]&lt;br /&gt;=&gt; "art"&lt;br /&gt;irb(main):051:0&gt; "artistic paella wake"[/[^\ba]{3}/]&lt;br /&gt;=&gt; "rti"&lt;br /&gt;irb(main):054:0&gt; "artistic paella wake"[/\ba/]&lt;br /&gt;=&gt; "a"&lt;br /&gt;irb(main):055:0&gt; "artistic paella wake"[/\ba./]&lt;br /&gt;=&gt; "ar"&lt;br /&gt;irb(main):058:0&gt; "people paella wake"[/\bp./]&lt;br /&gt;=&gt; "pe"&lt;br /&gt;irb(main):060:0&gt; "apostrophe paella wake"[/\bpa./]&lt;br /&gt;=&gt; "pae"&lt;br /&gt;irb(main):061:0&gt; "apostrophe paella wake"[/\bp./]&lt;br /&gt;=&gt; "pa"&lt;br /&gt;irb(main):062:0&gt; "apostrophe paella wake"[/\Bp./]&lt;br /&gt;=&gt; "po"&lt;br /&gt;irb(main):064:0&gt; "pancake paella wake"[/\Bp./]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):065:0&gt; "anticipated paella wake"[/\Bp./]&lt;br /&gt;=&gt; "pa"&lt;br /&gt;irb(main):066:0&gt; "anticipated paella wake"[/\Bp../]&lt;br /&gt;=&gt; "pat"&lt;br /&gt;irb(main):067:0&gt; "anticipated paella wake"[/\wp../]&lt;br /&gt;=&gt; "ipat"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jan 2008 11:04:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5062</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Shorthand Character Classes in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5054</link>
      <description>Learning Regular Expressions can seem tedious however with a little knowledge you can programmatically select or validate specific text in a few lines of code. key: \d = digit; \w = alphanumeric; \s space (includes tabs and line-breaks)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):462:0&gt; "happy"[/\d/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):463:0&gt; "happy"[/\w/]&lt;br /&gt;=&gt; "h"&lt;br /&gt;irb(main):464:0&gt; "123 happy"[/\w/]&lt;br /&gt;=&gt; "1"&lt;br /&gt;irb(main):465:0&gt; "123 happy"[/\d/]&lt;br /&gt;=&gt; "1"&lt;br /&gt;irb(main):466:0&gt; "123 happy"[/\d\s/]&lt;br /&gt;=&gt; "3 "&lt;br /&gt;irb(main):467:0&gt; "123 happy"[/\d{3}/]&lt;br /&gt;=&gt; "123"&lt;br /&gt;irb(main):468:0&gt; "123 happy"[/\d{3}\s\w{3}/]&lt;br /&gt;=&gt; "123 hap"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 30 Jan 2008 10:49:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5054</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Character sets in Regular Expressions</title>
      <link>http://snippets.dzone.com/posts/show/5052</link>
      <description>Here is a listing from my irb session, as you can see I'm learning character sets with regular expressions.  The characters ('a' and 'e') within the square brackets are treated as operands which are XORed between the characters 'h' and 'y'.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):155:0&gt; "hello"[/[ae]/]&lt;br /&gt;=&gt; "e"&lt;br /&gt;irb(main):156:0&gt; "hello"[/h[ae]y/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):157:0&gt; "hay"[/h[ae]y/]&lt;br /&gt;=&gt; "hay"&lt;br /&gt;irb(main):158:0&gt; "howdy"[/h[ae]y/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):159:0&gt; "hardy"[/h[ae]y/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):160:0&gt; "hardy"[/h[ae]/]&lt;br /&gt;=&gt; "ha"&lt;br /&gt;irb(main):161:0&gt; "hardy"[/h[ae]y/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):162:0&gt; "hoy"[/h[ae]y/]&lt;br /&gt;=&gt; nil&lt;br /&gt;irb(main):165:0&gt; "they"[/h[ae]y/]&lt;br /&gt;=&gt; "hey"&lt;br /&gt;irb(main):166:0&gt; "they would"[/h[ae]y/]&lt;br /&gt;=&gt; "hey"&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Jan 2008 18:46:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5052</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>singleton in ruby</title>
      <link>http://snippets.dzone.com/posts/show/2794</link>
      <description>// simple singleton&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Singleton &lt;br /&gt;  private_class_method :new&lt;br /&gt;  @@singleton = nil&lt;br /&gt;  &lt;br /&gt;  def Singleton.create&lt;br /&gt;    @@singleton = new unless @@singleton&lt;br /&gt;    @@singleton&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 07 Oct 2006 14:47:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2794</guid>
      <author>ovhaag (Oliver Haag)</author>
    </item>
  </channel>
</rss>
