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

The Archive Base Latest Questions

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

I am working in replacing a text with a hyperlink in C#. The problem

  • 0

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…

  • 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-23T13:54:10+00:00Added an answer on May 23, 2026 at 1:54 pm

    You need to escape like this:

    \\?
    

    You are escaping ? In the regex, but \ needs to also be escaped in the c# string.

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

Sidebar

Related Questions

I am working in replacing a text with a hyperlink in C#. The problem
I'm currently working on a problem that basically involves processing all data in a
I'm playing around with finding and replacing text. The only problem I'm having is
I'm working on replacing Unity with Ninject in the Prism framework. This requires me
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project that parses a log of events, and then updates a
I know that there are a few Questions here on SO relating to this,
The site I'm working on has a database table filled with glossary terms. I
I am working on a wiki bot for my communities wiki that uses the
I have a block of text that have to be parsed. It is kind

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.