Search

Thursday, January 11, 2007

Uppercase first Letter with CF RegEx

I needed to uppercase the first letter of a word before displaying it. Here is neat RegEx (CF specific but will probably work in Perl) that will do just that.
<cfset variable = rereplace(variable , '^(\w)(.*)', '\u\1\2') />
You can use the above when you need it done on the server. Here is the more elegant client side solution with CSS:
<span style="text-transform: capitalize;">boyan</span>
While I'm at it here is nice CF RegEx tester: http://www.cftopper.com/contentfiles/tools/regularExpTester.cfm
// //]]>