c# - Parsing Error while using special characters -


i want highlight search string in result set. when search string (java,php), code works fine. when search string (java,c++), getting parsing error when code executes line—

regexp = new regex(search_string.replace(" ", "|").trim(), regexoptions.ignorecase); 

i understand regex considers + , special characters, hence when search string (c++) – used separate regular expression mentioned below –

if (search_string.contains("++")) {     regexp = new regex(@"c\+{2}"); } 

i facing issues combine both these regex,so code works when search string (java,c++). can suggest resolution parsing error?

code snippet–

if (search_string.contains(","))             {                 search_string = search_string.replace(",", " ");             }         // regular expression setup , add or operator.         regexp = new regex(search_string.replace(" ", "|").trim(), regexoptions.ignorecase);          // highlight keywords calling delegate each time keyword found.         return regexp.replace(textinfo.totitlecase(inputtxt), new matchevaluator(replacekeywords));              public string replacekeywords(match m)          {              return "<span class=highlight>" + m.value + "</span>";          } 

you're looking regex.escape(), escape input string it's treated literal text regex engine.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -