<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: anchors code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 12:43:49 GMT</pubDate>
    <description>DZone Snippets: anchors code</description>
    <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>
  </channel>
</rss>
