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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:33:58+00:00 2026-05-25T12:33:58+00:00

OK, so I opened up this question yesterday and got an answer fairly quickly.

  • 0

OK, so I opened up this question yesterday and got an answer fairly quickly. It worked, or so I thought, so I marked it as the correct answer.

However I don’t think I explained the situation very well. Basically I am getting the HTML right before it is rendered, parsing it and searching for strings matching the pattern [tag|text x], where x is a number and the two words are case-insensitive.

However, as stated in the previous question, I would like to NOT replace these tags if they’re inside a textarea. This means that if they’re between </textarea> and <textarea...> then I would still like to replace them, but if they’re between <textarea...> and </textarea> then I would NOT like to replace them.

So far I have

@"(?<!\<textarea class='tag'\>)\[(tag|text) ([0-9]+)\]"

I have tried

@"(?<!\<textarea.[^>]*\>)\[(tag|text) ([0-9]+)\]"

but that doesn’t appear to work either.

For example I would like to replace any tags outside of the textareas in the following:

[tag 1]
<textarea>[tag 2]</textarea>[tag 3]
<textarea class="bob">Walter [tag 4]</textarea>[tag 5]
<textarea attr-1="fred">Jim [tag 6] Mary</textarea>[tag 7]
[tag 8]

In this example only tags 1, 3, 5, 7 and 8 should be replaced; 2, 4 and 6 should not.

Does anyone have any idea how what I should change it to in order to achieve this? I am not asking for anyone to just do all the work for me and give me the answer – I am in this to learn. I have struggled with this for a few hours now so any assistance with this would be great!

  • 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-25T12:33:59+00:00Added an answer on May 25, 2026 at 12:33 pm

    This kind of thing is usually easier to do with lookaheads than lookbehinds. This works as you requested:

    @"\[(tag|text)\s+(\d+)\](?![^<]*(?:<(?!/?textarea\b)[^<]*)*</textarea>)"
    

    The idea here is to look for a </textarea> tag, but only if you don’t encounter a <textarea...> tag first–that’s this part:

    [^<]*(?:<(?!/?textarea\b)[^<]*)*</textarea>
    

    Assuming the HTML is well formatted, that regex could only match inside a textarea element. Putting it in a negative lookahead which is executed after the [tag] has been matched causes matches in textareas to be rejected.

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

Sidebar

Related Questions

I didn't find any question like this here. Yesterday I finally got Gingerbread 2.3.4
This question nags me for a while but I did not found complete answer
I have this question you probably know the answer... My app is already functional
This question appeared when I recently opened a rather old driver for my raid
Guys, I opened this question (I hope could help some others) but reading stackoverflow
Hey guys, I don't know if this question has been asked yet but imagine
This question is a follow-up to one I asked and got answered here: How
Started with this question: OpenID. How do you logout OK. So OpenID does not
Referencing Is Facebook an OpenID provider? here. This is kind of an additional question
how can I make this jquery script close all previously opened children when entering

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.