<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ralph Holzmann &#187; Tags</title>
	<atom:link href="http://ralphholzmann.com/tag/tags/feed/" rel="self" type="application/rss+xml" />
	<link>http://ralphholzmann.com</link>
	<description>Web Development - jQuery, PHP, MySQL. In that order.</description>
	<lastBuildDate>Fri, 29 Jan 2010 14:01:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Strip Specific HTML Tags From String</title>
		<link>http://ralphholzmann.com/2009/12/10/strip-specific-html-tags-from-string/</link>
		<comments>http://ralphholzmann.com/2009/12/10/strip-specific-html-tags-from-string/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 18:17:35 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Strip]]></category>
		<category><![CDATA[Tags]]></category>

		<guid isPermaLink="false">http://ralphholzmann.com/?p=20</guid>
		<description><![CDATA[In fiddling around with some code highlighters to use for this blog, I found myself needing a way to strip tags from a JavaScript string of HTML, while leaving others. I needed it so I could convert highlighted code to &#8230; <a href="http://ralphholzmann.com/2009/12/10/strip-specific-html-tags-from-string/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In fiddling around with some code highlighters to use for this blog, I found myself needing a way to strip tags from a JavaScript string of HTML, while leaving others. I needed it so I could convert highlighted code to plain text so user&#8217;s could copy and paste code snippets without all the HTML garbage. This is what I came up with:</p>
<pre class="brush:js" jsbin="http://jsbin.com/inewo">var saveTags = new RegExp('&lt;(?!((\/)?(li|span)))(.)?([a-zA-Z?])[^&gt;&lt;]*&gt;', 'gi');

var html = '&lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span&gt;Some Text&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;';
var strippedHtml = html.replace(saveTags, '');

alert(html);          // &lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span&gt;Some Text&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
alert(strippedHtml);  // &lt;li&gt;&lt;span&gt;Some Text&lt;/span&gt;&lt;/li&gt;</pre>
<p>The <a href="http://www.w3schools.com/jsref/jsref_obj_regexp.asp">regex</a> matches all html tags<strong> except</strong> li and span. You then simply use the String method &#8216;<a href="http://www.w3schools.com/jsref/jsref_replace.asp">replace</a>&#8216; to replace the matches with an empty string. To edit the tags for the regex, simply change the tags in the expression, making sure to separate them with the bar &#8216;|&#8217; character.</p>
<p>After figuring out how to strip the specific tags , I didn&#8217;t even end up using it because I moved from <a href="http://code.google.com/p/jquery-chili-js/">jQuery Chili 2.2</a> to <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">SyntaxHighlighter</a> which has a built in source code viewer, but I thought the information was valuable nonetheless.</p>
]]></content:encoded>
			<wfw:commentRss>http://ralphholzmann.com/2009/12/10/strip-specific-html-tags-from-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
