c# - Complex Regex problem with hyperlink not matching "?" -


i working in replacing text hyperlink in c#. problem here link has question mark

case 1:no problem

input: asass123

output:asass123

case 2:problem here

input: asasq123

output:asasq123">asasq123

(note: first occurrence of asass123 hyperlink , replaced http://stack.com/temp/test?order=sam&identifier=<a href= , second occurrence plain text)

preferred output: asasq123

how can rectify problem. code here 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 "?" found in second argument. if rid of "?" in both 2nd , 3rd arguments, works fine.

but cannot rid of "?", because needed url function. how can solve problem?

i tried escape sequence \? , c sharp says escape sequence unrecognized...

you need escape this:

\\? 

you escaping ? in regex, \ needs escaped in c# string.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -