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

  • Home
  • SEARCH
  • 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 5983679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:15:56+00:00 2026-05-22T22:15:56+00:00

I was wondering how to match a line not containing a specific word using

  • 0

I was wondering how to match a line not containing a specific word using Python-style Regex (Just use Regex, not involve Python functions)?

Example:

PART ONE OVERVIEW 1 
Chapter 1 Introduction 3

I want to match lines that do not contain the word “PART”?

  • 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-22T22:15:57+00:00Added an answer on May 22, 2026 at 10:15 pm

    This should work:

    /^((?!PART).)*$/
    

    Edit (by request): How this works

    The (?!...) syntax is a negative lookahead, which I’ve always found tough to explain. Basically, it means "whatever follows this point must not match the regular expression /PART/." The site I’ve linked explains this far better than I can, but I’ll try to break this down:

    ^         #Start matching from the beginning of the string.    
    (?!PART)  #This position must not be followed by the string "PART".
    .         #Matches any character except line breaks (it will include those in single-line mode).
    $         #Match all the way until the end of the string.
    

    The ((?!xxx).)* idiom is probably hardest to understand. As we saw, (?!PART) looks at the string ahead and says that whatever comes next can’t match the subpattern /PART/. So what we’re doing with ((?!xxx).)* is going through the string letter by letter and applying the rule to all of them. Each character can be anything, but if you take that character and the next few characters after it, you’d better not get the word PART.

    The ^ and $ anchors are there to demand that the rule be applied to the entire string, from beginning to end. Without those anchors, any piece of the string that didn’t begin with PART would be a match. Even PART itself would have matches in it, because (for example) the letter A isn’t followed by the exact string PART.

    Since we do have ^ and $, if PART were anywhere in the string, one of the characters would match (?=PART). and the overall match would fail. Hope that’s clear enough to be helpful.

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

Sidebar

Related Questions

Using Python Regex, I was wondering how to match the patterns (Exercises...) and (Chapter...)
I'm wondering, is it possible to use regex to match a word after a
I am wondering why the following regex does not match. string query = \1
I'm just wondering if it's possible to use one regular expression to match another,
I just wondering, how can write web applications or web pages using LaTeX-styled math?
I'm wondering if its possible to use string substitution along with the python re
I was wondering how can I match two digits but which are not the
I'm wondering if the following is possible: The method Regex.Match can receive an enum,
Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality.
Wondering if there's any not-too-hard way to edit non-form text in html 4. I

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.