Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 105131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:23:27+00:00 2026-05-11T01:23:27+00:00

In some regex flavors, [negative] zero-width assertions (look-ahead/look-behind) are not supported. This makes it

  • 0

In some regex flavors, [negative] zero-width assertions (look-ahead/look-behind) are not supported.

This makes it extremely difficult (impossible?) to state an exclusion. For example ‘every line that does not have ‘foo’ on it’, like this:

^((?!foo).)*$ 

Can the same thing be achieved without using look-around at all (complexity and performance concerns set aside for the moment)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:23:27+00:00Added an answer on May 11, 2026 at 1:23 am

    UPDATE: It fails ‘with two ff before oo’ as @Ciantic pointed out in the comments.


    ^(f(o[^o]|[^o])|[^f])*$ 

    NOTE: It is much much easier just to negate a match on the client side instead of using the above regex.

    The regex assumes that each line ends with a newline char if it is not then see C++’s and grep’s regexs.

    Sample programs in Perl, Python, C++, and grep all give the same output.

    • perl

      #!/usr/bin/perl -wn print if /^(f(o[^o]|[^o])|[^f])*$/; 
    • python

      #!/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) 
    • c++

      #include <iostream> #include <string> #include <boost/regex.hpp>  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 << line << std::endl; } 
    • grep

      $ grep '^\(f\(o\([^o]\|$\)\|\([^o]\|$\)\)\|[^f]\)*$' in.txt 

    Sample file:

    foo 'foo' abdfoode abdfode abdfde abcde f  fo foo fooo ofooa ofo ofoo 

    Output:

    abdfode abdfde abcde f  fo ofo 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Regex, it looks like this: string regexForDrop = @^((%27)|'|(\-\-))\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50)$; It works
Hi I'm struggling with some regex I've got a string like this: a:b||c:{d:e||f:g}||h:i basically
While doing some small regex task I came upon this problem. I have a
I already have some regex logic which says to look for a div tag
Here is proof that my site is not portable. I had some regex that
I am working on some regex and I wonder why this regex (?<=(.*?id(( *)=)\\s[\\']))g
While using some regex in C#, I'm facing the following problem : Consider this
I've been trying to do some regex operations in PHP, and I'm not very
Is it possible to do something like this? var pattern = /some regex segment/
I'm trying to figure out the reason behind some regex comparison results I'm getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.