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 Say I have the following code: // a class like this
I have a mathematical formula in my program that takes in two values, both
Long story short, I need to get the total scroll size for a text
Short story: The NSArrayController's selection is being reset whenever setContent is issued. I am
i have been tasked with changing a bit of css for a site that
this may be a simple question but i was wondering, i have an application
Short question: Can I change the DOCTYPE of my existing XHTML 1.0 website to
I'm trying to search the classpath in my project at runtime. We use Maven
First stackoverflow question! I've searched...I promise. I haven't found any answers to my predicament.
I've been putting on with a strange issue in my iPhone program for a

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.