Note that there are some explanatory texts on larger screens.

plurals
  1. POHow .{n} and ?<option>: works in `Regexp` on Ruby 1.9.3 environment
    primarykey
    data
    text
    <p>I was trying to understand how <code>.{n}</code> and <code>?&lt;option&gt;:</code> works in <code>Regexp</code> on Ruby 1.9.3 environment. But couldn't understand how the below code produce the output:</p> <pre><code>irb(main):001:0&gt; %W{fin\n fi\n\n \n\n fin\r\n find}.grep /f.{2}(?m:.)\Z/ =&gt; ["fin\n", "fin\r\n", "find"] irb(main):002:0&gt; %W{fin\n fi\n\n \n\n fin\r\n find}.grep /f.{1}(?m:.)\Z/ =&gt; ["fin\n", "fi\n\n"] irb(main):003:0&gt; %W{fin\n fi\n\n \n\n fin\r\n find}.grep /f.{1}(?m:.)\Z/ =&gt; [] irb(main):010:0&gt; %W{fin\n fi\n\n \n\n fin\r\n find}.grep /f.(?m:.)\Z/ =&gt; ["fin\n", "fi\n\n"] irb(main):011:0&gt; %W{fin\n fi\n\n \n\n fin\r\n find}.grep /f.(m:.)\Z/ =&gt; [] irb(main):012:0&gt; %W{fin\n fi\n\n \n\n fin\r\n find}.grep /f.(?m:.)\z/ =&gt; [] </code></pre> <p>Can anyone help me to understand how the above code worked to generate the mentioned output in <code>IRB</code> terminal?</p> <p>Thanks,</p> <hr> <p><strong><em>As per @Kevin last paragraph</em></strong> I tried below and found expected and desirable output :</p> <pre><code>irb(main):014:0&gt; %W{fin fi\n\n \n\n fin\r\n find}.grep /f.(?m:.)\z/ =&gt; ["fin"] irb(main):015:0&gt; %W{fin fi\n\n \n\n fin\r find}.grep /f.(?m:.)\z/ =&gt; ["fin"] irb(main):016:0&gt; %W{fin fi\n \n\n fin\r\n find}.grep /f.(?m:.)\z/ =&gt; ["fin", "fi\n"] irb(main):017:0&gt; %W{fin fi\n \n\n fr\n find}.grep /f.(?m:.)\z/ =&gt; ["fin", "fi\n", "fr\n"] irb(main):018:0&gt; </code></pre> <p>Thank you very much <strong><em>@Kevin</em></strong> . You helped me to understand the whole concept!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload