Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE:</strong> It fails "with two ff before oo" as <a href="https://stackoverflow.com/questions/466053/regex-matching-by-exclusion-without-look-ahead-is-it-possible/466167#comment80765384_466167">@Ciantic pointed out in the comments.</a></p> <hr> <pre><code>^(f(o[^o]|[^o])|[^f])*$ </code></pre> <p><strong>NOTE:</strong> It is much much easier just to negate a match on the client side instead of using the above regex. </p> <p>The regex assumes that each line ends with a newline char if it is not then see C++'s and grep's regexs. </p> <p>Sample programs in Perl, Python, C++, and <code>grep</code> all give the same output.</p> <ul> <li><p><a href="http://ideone.com/90iZj" rel="nofollow noreferrer">perl</a></p> <pre><code>#!/usr/bin/perl -wn print if /^(f(o[^o]|[^o])|[^f])*$/; </code></pre></li> <li><p><a href="http://ideone.com/3CYA6" rel="nofollow noreferrer">python</a></p> <pre><code>#!/usr/bin/env python import fileinput, re, sys from itertools import ifilter re_not_foo = re.compile(r"^(f(o[^o]|[^o])|[^f])*$") for line in ifilter(re_not_foo.match, fileinput.input()): sys.stdout.write(line) </code></pre></li> <li><p>c++</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;boost/regex.hpp&gt; int main() { boost::regex re("^(f(o([^o]|$)|([^o]|$))|[^f])*$"); //NOTE: "|$"s are there due to `getline()` strips newline char std::string line; while (std::getline(std::cin, line)) if (boost::regex_match(line, re)) std::cout &lt;&lt; line &lt;&lt; std::endl; } </code></pre></li> <li><p><a href="http://ideone.com/kjO0J" rel="nofollow noreferrer">grep</a></p> <pre><code>$ grep "^\(f\(o\([^o]\|$\)\|\([^o]\|$\)\)\|[^f]\)*$" in.txt </code></pre></li> </ul> <p>Sample file:</p> <pre><code>foo 'foo' abdfoode abdfode abdfde abcde f fo foo fooo ofooa ofo ofoo </code></pre> <p>Output:</p> <pre><code>abdfode abdfde abcde f fo ofo </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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