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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:47:18+00:00 2026-05-11T21:47:18+00:00

Long story short, I have two regex patterns. One pattern matches things that I

  • 0

Long story short, I have two regex patterns. One pattern matches things that I want to replace, and the other pattern matches a special case of those patterns that should not be replace. For a simple example, imagine that the first one is “\{.*\}” and the second one is “\{\{.*\}\}”. Then “{this}” should be replaced, but “{{this}}” should not. Is there an easy way to take a string and say “substitute all instances of the first string with “hello” so long as it is not matching the second string”?

In other words, is there a way to make a regex that is “matches the first string but not the second” easily without modifying the first string? I know that I could modify my first regex by hand to never match instances of the second, but as the first regex gets more complex, that gets very difficult.

  • 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-11T21:47:18+00:00Added an answer on May 11, 2026 at 9:47 pm

    You can give replace a function (reference)

    But make sure the first regex contain the second one. This is just an example:

    regex1 = re.compile('\{.*\}')
    regex2 = re.compile('\{\{.*\}\}')
    
    def replace(match):
        match = match.group(0)
        if regex2.match(match):
            return match
        return 'replacement'
    
    
    regex1.sub(replace, data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short, I have a substantial Python application that, among other things, does
Long story short, I have a struct (see below) that contains exactly one field:
Long story short, I have a long code that uses jQuery. Lots of files,
Long story short: I have 2 collections of objects. One contains good values (Let's
Long story short - I have an editable <div> and I want to clear
Long story short: I have some controller logic that requests a value from the
Long story short -- we have 2 webservers that run a 3rd party asp.net
To make a long story short, I have dynamic pages on a website that
To make a long story short I have to use processing in a class
Long story short, I have an ASP.NET application I'm trying to debug and at

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.