Link to home
Start Free TrialLog in
Avatar of BeginningWebDesign
BeginningWebDesign

asked on

Variables in regular expressions problem

Hi

Can anyone tell me where I'm going wrong here.
string HighlightWord, Word1;

If I run the code below it works OK
HighlightWord = Regex.Replace(HighlightWord, "harry", "<strong>harry</strong>", RegexOptions.IgnoreCase);

But when I try and change harry to a variable it will not work, can anyone tell me what I need to change

HighlightWord = Regex.Replace(HighlightWord, "Word1", "<strong>Word1</strong>", RegexOptions.IgnoreCase);

Regards
Caz
Avatar of AaronReams
AaronReams

is this what you're trying to do?

string Word1 = "Word1";
HighlightWord = Regex.Replace(HighlightWord, Word1, "<strong>Word1</strong>", RegexOptions.IgnoreCase);
Its strange... Does HighlightWord string has "Word1"? If it has, surely it must get replaced by "<strong>Word1</strong>".
ASKER CERTIFIED SOLUTION
Avatar of sukumar_diya
sukumar_diya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BeginningWebDesign,

There is something wrong with your question. Wanna fix your question, rephrase it or whatever,  so we'll understand better?

:-)
Avatar of BeginningWebDesign

ASKER

Thanks sukumar_diya

That fixed that problem, and has caused another problem. As I only asked how to highlight a variable which you answered, I have opened another question with the new problem.

Caz