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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:24:26+00:00 2026-05-24T02:24:26+00:00

I am facing a problem to match and replace certain words, not contained in

  • 0

I am facing a problem to match and replace certain words, not contained in http://

Present Regex:

 http://.*?\s+

This matches the pattern http://www.egg1.com http://www.egg2.com

I need a regex to match certain words contained outside the http://

Example:

"This is a sample. http://www.egg1.com and http://egg2.com. This regex will only match 
 this egg1 and egg2 and not the others contained inside http:// "

 Match: egg1 egg2

 Replaced: replaced1 replaced2

Final Output :

 "This is a sample. http://www.egg1.com and http://egg2.com. This regex will only 
  match this replaced1 and replaced2 and not the others contained inside http:// "

QUESTION:
Need to match certain patterns (as in example : egg1 egg2) unless they are part of http:// .Do not match egg1 and egg2 if they are present within http://

  • 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-24T02:24:27+00:00Added an answer on May 24, 2026 at 2:24 am

    One solution I can think of is to form a combined pattern for HTTP-URLs and your pattern, then filter the matches accordingly:

    import re
    
    t = "http://www.egg1.com http://egg2.com egg3 egg4"
    
    p = re.compile('(http://\S+)|(egg\d)')
    for url, egg in p.findall(t):
      if egg:
        print egg
    

    prints:

    egg3
    egg4
    

    UPDATE: To use this idiom with re.sub(), just supply a filter function:

    p = re.compile(r'(http://\S+)|(egg(\d+))')
    
    def repl(match):
        if match.group(2):
            return 'spam{0}'.format(match.group(3))
        return match.group(0)
    
    print p.sub(repl, t)
    

    prints:

    http://www.egg1.com http://egg2.com spam3 spam4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing a problem with IE6. I took the toggle function from this website
I'm facing this problem again and again, but can't find any solution (except mine,
I am really really tired these day because of facing this problem. I am
I am facing problem with an Oracle Query in a .net 2.0 based windows
I am facing problem with the control flajaxian.FileUploader i.e. after downloading the dll file
I am new to struts 2. I am facing problem in filling Select tag
When facing the problem of validating a property in a JSF2 application there are
I am facing a problem with .NET generics. The thing I want to do
I am facing a problem. I would like to localize my action names in
I'm facing a problem while unit testing my forms. The problem is that data

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.