c# - Problem using Regex.Replace when text containing $ and using \b boundry -


have following problem using regex , $ in string. wondring if can assist.

bla in text below random words.

string text = "<id='$text1$text2$text3'><div>bla bla bla text3 bla bla</div>"; string pattern = "\btext3\b"; text = regex.replace(text, pattern, "####"); 

if above, replace both text3. want change value in div element result becomes: <id='$text1$text2$text3'> <div>bla bla bla #### bla bla</div>.

thanks in advance!

string pattern = @"\btext3\b(?![^<>]*>)"; 

this quick-and-dirty solution relies on several simplifying assumptions, regexes must if they're used on html. example, assumes there never angle brackets in attribute values. that's legal (in html @ least), it's extremely rare in practice.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -