Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Regex are powerful, but you'll find they also often add needless complexity to a problem.</p> <p>This is how I'd go about the problem:</p> <pre><code>text = &lt;&lt;EOT The starting point,obviously,is a thorough analysis ofthe intellectual property portfolio,the contents ofwhich can be broadly divided into two categories:property that is in use and property that is not in use ========== Essentials of Licensing Intellectual Property (Alexander I. Poltorak, Paul J. Lerner) - Highlight on Page 25 | Added on Friday, 25 November 11 10:53:36 Greenwich Mean Time commentators (a euphemism for prolific writers with little experience ========== Essentials of Licensing Intellectual Property (Alexander I. Poltorak, Paul J. Lerner) - Highlight on Page 26 | Added on Friday, 25 November 11 10:54:29 Greenwich Mean Time EOT text.each_line do |l| l.chomp! next if ((l =~ /\AEssentials/) .. (l =~ /Time\z/)) puts l end </code></pre> <p>Which outputs:</p> <pre><code>The starting point,obviously,is a thorough analysis ofthe intellectual property portfolio,the contents ofwhich can be broadly divided into two categories:property that is in use and property that is not in use ========== commentators (a euphemism for prolific writers with little experience ========== </code></pre> <p>This works because the <code>..</code>, AKA range operator, gains new capability when used with an <code>if</code>, and turns into what we call the flip-flop operator. In operation what happens is <code>((l =~ /\AEssentials/) .. (l =~ /Time\z/))</code> returns false, until <code>(l =~ /\AEssentials/)</code> matches. From then until <code>(l =~ /Time\z/)</code> matches it returns true. Once the final regex matches it returns to returning false. </p> <p>This behavior works really well for extracting sections from text.</p> <p>If you are aggregating text, for subsequent output, replace the <code>puts l</code> with something to append <code>l</code> to a buffer, then output that buffer at the end of your run.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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