<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Cutter&apos;s Crossing - regex</title>
			<link>http://www.cutterscrossing.com/index.cfm</link>
			<description>ColdFusion Development, Life, and Other Stuff</description>
			<language>en-us</language>
			<pubDate>Sun, 19 May 2013 01:00:13 -0400</pubDate>
			<lastBuildDate>Sun, 27 Feb 2011 14:15:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>web.admin@cutterscrossing.com</managingEditor>
			<webMaster>web.admin@cutterscrossing.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>web.admin@cutterscrossing.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			<item>
				<title>Java RegEx replaceAll In ColdFusion</title>
				<link>http://www.cutterscrossing.com/index.cfm/2011/2/27/Java-RegEx-replaceAll-In-ColdFusion</link>
				<description>
				
				In an odd turn, I was given text like below to display on a page.

&lt;code&gt;
Some Title&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;A.&amp;amp;nbsp;&amp;amp;nbsp;Some&amp;amp;nbsp;subheader&amp;amp;nbsp;here&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;B.&amp;amp;nbsp;&amp;amp;nbsp;Some&amp;amp;nbsp;other&amp;amp;nbsp;subheader&amp;amp;nbsp;here&lt;br /&gt;
&lt;/code&gt;

Two issues here (aside from the fact that it should have been an HTML list): 1) it needed to retain the spacing format, and 2)it needed to wrap within a sized element. A non-breaking space, when viewed, appears as a space ( ), but isn&apos;t an actual space, so the browser doesn&apos;t know where to break the text when wrapping it in an element. Hmmmm....So, we needed to replace any &amp;amp;nbsp; that is preceded and followed by a printable character, leaving multiple concurrent &amp;amp;nbsp; in tact for the fake indentation. I figured this was best left to a RegEx expression used in ColdFusion&apos;s ReReplace() method, but my RegEx is pretty rusty, so I reached out on Twitter.

&lt;a href=&quot;http://www.andymatthews.net/&quot; target=&quot;_blank&quot;&gt;Andy Matthews&lt;/a&gt; and &lt;a href=&quot;http://twitter.com/krisplus5&quot; target=&quot;_blank&quot;&gt;Kris Jones&lt;/a&gt; both reached out to me with possible expressions for this, but nothing was working. What was happening is it was finding the characters around an &amp;amp;nbsp; and removing both the nonbreaking space &lt;em&gt;and&lt;/em&gt; the characters. Hmmmm....

But both of these folks had pointed me in the right direction. Seems in some RegEx replace engines you can reference &lt;em&gt;groups&lt;/em&gt; within expressions in your replacement output. Unfortunately, you can&apos;t do this with ReReplace() (or if you can I haven&apos;t figured out how).

So I said to myself, &quot;Self&quot; (&apos;cause that&apos;s what I call myself) &quot;Self, what about tapping into ColdFusion&apos;s underlying Java?&quot; Fingers flying I hit Google. BAM! Up pops &lt;a href=&quot;http://http://www.bennadel.com&quot; target=&quot;_blank&quot;&gt;Ben Nadel&lt;/a&gt; talking pattern matching with the underlying java.util.regex package, with code examples all over (here&apos;s &lt;a href=&quot;http://www.bennadel.com/blog/2094-Turning-Modes-On-And-Off-Within-A-Regular-Expression.htm&quot; target=&quot;_blank&quot;&gt;one&lt;/a&gt;). Time to play.

First I needed the Java RegEx Pattern object:

&lt;code&gt;
    CreateObject(&quot;java&quot;,&quot;java.util.regex.Pattern&quot;)
&lt;/code&gt;

Then I needed to define the pattern for which I was searching. This &lt;a href=&quot;http://mindprod.com/jgloss/regex.html&quot; target=&quot;_blank&quot;&gt;RegEx Glossary&lt;/a&gt; gave me a ton of info on Java RegEx, that I used to define my matching pattern:

&lt;code&gt;
    .compile(javaCast(&quot;string&quot;,&quot;(\p{Print})&amp;amp;nbsp;(\p{Print})&quot;))
&lt;/code&gt;

the \p{Print} identifies any printable character (don&apos;t want to include my &lt;br /&gt; tags), and want only nonbreaking spaces bracketed by printable characters. The next step is defining the matcher (what the expression will be run against):

&lt;code&gt;
    .matcher(javaCast(&quot;string&quot;,REQUEST.matchThis))
&lt;/code&gt;

And then, the final step, replacing the &amp;amp;nbsp; with a space. The expression returns the characters as well, so I need group 1 + space + group 2 in my output (what I couldn&apos;t do in ReReplace). That RegEx Glossary helped with this too:

&lt;code&gt;
    .replaceAll(&quot;$1 $2&quot;)
&lt;/code&gt;

The groups in the expression, the bits within parens (), are available to your output of the replaceAll by referencing that part of the expression&apos;s value. $1 for the first group, $2 for the second, and so on. The entire thing then looks something like this:

&lt;code&gt;
    REQUEST.finalValue =     CreateObject(&quot;java&quot;, &quot;java.util.regex.Pattern&quot;).compile(javaCast(&quot;string&quot;, &quot;(\p{Print})&amp;amp;nbsp;(\p{Print})&quot;)).matcher(javaCast(&quot;string&quot;, REQUEST.matchThis)).replaceAll(&quot;$1 $2&quot;);
&lt;/code&gt;

Worked like a charm! Thanks to all who helped me get my head around this one.
				</description>
				
				<category>regex</category>
				
				<category>ColdFusion</category>
				
				<category>Development</category>
				
				<pubDate>Sun, 27 Feb 2011 14:15:00 -0400</pubDate>
				<guid>http://www.cutterscrossing.com/index.cfm/2011/2/27/Java-RegEx-replaceAll-In-ColdFusion</guid>
				
				
			</item>
			</channel></rss>