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 4335870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:43:45+00:00 2026-05-21T10:43:45+00:00

I’ve seen examples of finding the absence of characters in a regular expression, I’m

  • 0

I’ve seen examples of finding the absence of characters in a regular expression, I’m trying to find the absence of words in a regular expression (likely using a negative lookbehind).

I have lines of code like this:

Example One:

protected static readonly string BACKGROUND_MUSIC_NAME = "Music_Mission_Complete_Loop_audio";

And here’s another one:

mainWindow.Id = "MainWindow";

Final one:

mainStoLabel.Text = "#stb_entry_clah";

I want to capture only the middle one by finding all strings like these that a.) aren’t preceded by a “#” in the actual string between the quotes, and b.) aren’t preceded at all by the word “readonly”.

My current Regular Expression is this:

.*\W\=\W"[^#].*"

It captures the top two examples. Now I just want to narrow down the top example. How do I capture the absence of (not characters) whole words.

Thanks.

  • 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. Editorial Team
    Editorial Team
    2026-05-21T10:43:46+00:00Added an answer on May 21, 2026 at 10:43 am

    The bug in your negation lookahead assertion is that you didn’t put it together right to suit the general case. You need to make its assertion apply to every character position as you crawl ahead. It only applies to one possible dot the way you’ve written it, whereas you need it to apply to all of them. See below for how you must do this to do it correctly.

    Here is a working demo that shows two different approaches:

    1. The first uses a negative lookahead to ensure that the left-hand portion not contain readonly and the right-hand portion not start with a number sign.

    2. The second does a simpler parser, then separately inspects the left- and right-hand sides for the individual constraints that apply to each.

    The demo language is Perl, but the same patterns and logic should work virtually everywhere.

    #!/usr/bin/perl
    
    while (<DATA>) {
        chomp;
    #
    # First demo: use a complicated regex to get desired part only
    #
        my($label) = m{
            ^                           # start at the beginning
            (?:                         # noncapture group:
                (?! \b readonly \b )    #   no "readonly" here
                .                       #   now advance one character
            ) +                         # repeated 1 or more times
            \s* = \s*                   # skip an equals sign w/optional spaces
            " ( [^#"] [^"]* ) "         # capture #1: quote-delimited text
                                        #   BUT whose first char isn't a "#"
        }x;
    
        if (defined $label) {
            print "Demo One: found label <$label> at line $.\n";
        }
    #
    # Second demo: This time use simpler patterns, several
    #
        my($lhs, $rhs) = m{
            ^                       # from the start of line
            ( [^=]+ )               # capture #1: 1 or more non-equals chars
            \s* = \s*               # skip an equals sign w/optional spaces
            " ( [^"]+ ) "           # capture #2: all quote-delimited text
        }x;
    
        unless ($lhs =~ /\b readonly \b/x || $rhs =~ /^#/) {
            print "Demo Two: found label <$rhs> at line $.\n";
        }
    
    }
    __END__
    protected static readonly string BACKGROUND_MUSIC_NAME = "Music_Mission_Complete_Loop_audio";
    mainWindow.Id = "MainWindow";
    mainStoLabel.Text = "#stb_entry_clah";
    

    I have two bits of advice. The first is to make very sure you ALWAYS use /x mode so you can produce documented and maintainable regexes. The second is that it is much cleaner doing things a bit at a time as in the second solution rather than all at once as in the first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.