I am working in replacing a text with a hyperlink in C#. The problem here is that the link has a question mark
Case 1:No problem
Input: ASAss123
Output:ASAss123
Case 2:Problem here
Input: ASAsq123
Output:ASAsq123">ASAsq123
(Note: First occurrence of ASAss123 is hyperlink and is replaced as http://stack.com/temp/test?order=sam&identifier=<a href= and second occurrence is just plain text)
Preferred Output: ASAsq123
How can I rectify this problem. Code here for your reference:
mailItem.HTMLBody = Regex.Replace(
mailItem.HTMLBody,
"(?<!http://stack.com/temp/test?order=sam&identifier=)ASA[a-z][a-z][0-9][0-9][0-9](?!</a>)",
"<a href=\"http://stack.com/temp/test?order=sam&identifier=$&\">$&</a>");
The problem here is with the "?" found in the second argument. If I get rid this of "?" in both 2nd and 3rd arguments, this works perfectly fine.
But I cannot get rid of "?", because it is needed for the URL to function. How can I solve this problem?
I tried escape sequence with \? and C sharp says escape sequence unrecognized...