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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:00:40+00:00 2026-06-05T20:00:40+00:00

I want to replace a regex with ‘*’, but only if the regex is

  • 0

I want to replace a regex with ‘*’, but only if the regex is out side of <>. The whole point is to not interfere with the html tags.

I use this to replace:

re.sub(r'SOMEREGEX(?=[^>]*(<|$))', '*', line)

However I ran into his problem: if my regex is:

f.*k

Then this:

fzzzzzzzzz<HTMLTAG>zzzzzzzk

Would become an ‘*’, which I don’t want. How do I overcome this problem?

Constraints:

-All brackets are matched

-No nested brackets

-SOMEREGEX is provided by the user. I prefer not changing that.

  • 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-06-05T20:00:42+00:00Added an answer on June 5, 2026 at 8:00 pm

    You could try replacing the . character – “any character at all” – with the character class [^<>], which matches any character except the angle brackets, <>. This would give the regex f[^<>]*k. This would match facebook but not face<b>book.

    There are still things that can go wrong with this, though. Have you considered using a proper HTML parser instead of regular expressions? BeautifulSoup is easy, tasty and fun.

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

Sidebar

Related Questions

I want to use regex to replace src html attributes. The HTML is not
I'm not that good with this REGEX string replace, but i think this problem
why this regex not work? i want to replace my string by all not
I want do replace why this code don't work? MessageBox.Show( Regex.Replace(Regex.Escape(@c:\www\html), Regex.Escape(@c:\www\), , RegexOptions.IgnoreCase));
I want to replace some HTML tags that I have in a CDATA element,
I want to replace \n with <br /> in a string. But not that
I want to replace only the first occurrence of a word in a sentence
I want to replace all mailto: links in html with plain emails. In: text
I want to use Regex.Replace() to loop through a string containing words that are
I want to be able to use a RegEx to parse out ranges like

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.