I'm writing a custom HTML mark-up form that will take in text and format it in a specified way. One of the functions is to add <span> tags to certain subheader phrases and words. What I want to do is to be able to highlight the subheader phrase and then use Regex to take the selected text and replace all other instances of it, except for those that already have span tags. For instance:
For the most part, it seems to be working, but I've found that it replaces partial matches as well. For instance, highlighting "Who" replaces any instance of "W" or "Wh" as well. Any thoughts as to how to fix this? I'm using .NET 4.0. Thanks in advance!
Sorry for the double post, but the highlighted phrase I was having problems with is actually "Who?" and I realize now the question mark is probably screwing up the syntax. Do I need to escape the question mark? How would you do that with selected text?
You can escape your string with Regex.Escape but I don't think that's your only problem. If you are just surrounding the current selection with <span> tag why don't you just replace your current selection with simple string operation using TextBox.SelectionStart and TextBox.SelectionLength ?
Bogdan
If someone helped you then please Rate his post and mark the thread as Resolved
Please improve your messages appearance by using tags[ code] Place your code here [ /code]
I wanted it to be able to take the selected string, search the rest of the document for the same string (the documents that it will be marking up will always have multiple instances of the subheader phrase) and then add span tags to those as well. Is there an efficient way to do that without regular expressions?
Bookmarks