/ Published in: ActionScript 3
If there is ever a time when you load text from an external source containing unwanted HTML markup use the following function. This uses a regular expression to strip all HTML tags from the input string. The string "<strong>Click <a href='http://example.com'>here</a> to find out more</strong>" would simply be converted to "Click here to find out more.". This returns a new string, leaving the input string unchanged.
Expand |
Embed | Plain Text
function stripTags(string:String):String { var s:String = string; var regexp:RegExp = new RegExp("<[^<]*<", "gi"); return s.replace(regexp, ""); }
Comments
Subscribe to comments
You need to login to post a comment.

I think the final less-than symbol should be a greater-than symbol.
Yes it should. Thanks this was useful.