regex - Replace < and > symbols with &lt; and &gt; symbols in HTML String -


i want regular expression replace < , > symbols &lt; , &gt; in html text , make valid xml.

example string:

<html><body><p style="margin:0px">his <span style="color: rgb(237, 23, 23);">career </span>spanned development of cinema, <span style="font-weight: 700;">silent film</span>, through experiments in <span style="text-transform: uppercase;">technicolor </span>to filmmaking in 21st century.​</p><p>his career spanned development of cinema, silent film, through experiments in technicolor filmmaking in 21st century.<this sample></p>​</body></html> 

result:

<html><body><p style="margin:0px">his <span style="color: rgb(237, 23, 23);">career </span>spanned development of cinema, <span style="font-weight: 700;">silent film</span>, through experiments in <span style="text-transform: uppercase;">technicolor </span>to filmmaking in 21st century.​</p><p>his career spanned development of cinema, silent film, through experiments in technicolor filmmaking in 21st century.&lt;this sample&gt;</p>​</body></html> 

thanks

iyyappan s

that should it:

private function replacetags(string:string):string {     string = string.replace(/</gi, "&lt;");     string = string.replace(/>/gi, "&gt;");      return string; }  trace("replaced string: " + replacetags("string < >")); 

another option wrap text cdata in xml


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -