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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:23:54+00:00 2026-05-24T19:23:54+00:00

I am currently writing a program that formats certain words in a Rich Text

  • 0

I am currently writing a program that formats certain words in a Rich Text document by putting RTF tags around them.

As the program allows for additional formatting rules that can overlap (i.e. colouring the phrase “please help me” all in yellow and colouring “please” in blue), the program has difficulty finding matches that have already been formatted by a previous rule (i.e. “please help me”, from the previous example becomes “\cf1 please\cf0 help me”, which will not match the other rule.

I have been getting around this by using regular expressions and putting an expression that matches any RTF tag after each character in the phrase (as the rules are defined by the user, and I don’t know the specific point of overlap), like this:

line = Regex.Replace(line, @"\bP(?:\\[^ ]* )*l(?:\\[^ ]* )*e(?:\\[^ ]* )*a(?:\\[^ ]*   )*s(?:\\[^ ]* )*e(?:\\[^ ]* )*", Evaluator);

The ‘(?:\\[^ ]* )*’ expression in the above sequence finds the preceding character regardless of any tags after it, but doing this with every rule slows down the code drastically and requires me to generate a regular expression for each one; which may not work as expected depending on the rule.

Err, sorry for the wall of text, I’ll get to the point now. Does anyone know a more efficient way of finding a word that has RTF tags inside it at an unknown point?

  • 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-24T19:23:55+00:00Added an answer on May 24, 2026 at 7:23 pm

    One possibility is to never allow overlap of similar tags – if you need to start formatting the text in red but it’s already being formatted in blue, close the blue tag before you start the red tag. Otherwise I’d imagine that the formatting rules could get quite ambiguous.

    Edit

    If you absolutely need to have overlap, then create a stack of formatting. End the old tag as I said above, but save it to the stack. Start the new tag, and when your new tag is done, if the old formatting was not closed (and is still in the stack) start the old formatting again. Whenever you close a tag you remove it from the stack.

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

Sidebar

Related Questions

I'm currently writing a program that has debug output strewn throughout it. This is
I'm currently writing a little GUI program that does some work and exits afterwards.
I am currently writing a program that reads records from a txt file and
I am currently writing a program that I need to send to a friend
I'm currently writing a program to generate really enormous (65536x65536 pixels and above) Mandelbrot
I am currently writing a simple, timer-based mini app in C# that performs an
I'm writing a cross-platform Qt-based program that from time to time needs to play
I'm currently writing a C# console app that generates a number of URLs that
I am writing an iphone (IOS 4) program that capture live video from the
I am currently writing a non-web program using mostly python and have gotten to

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.