<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: lookbehind code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 03:47:22 GMT</pubDate>
    <description>DZone Snippets: lookbehind code</description>
    <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>
  </channel>
</rss>
