How to access underlying Java regular expression functionality in ColdFusion to get around "RE" function limitations
Coldfusion Add commentsCurrently in ColdFusion there are functions that easily provide regular expression functionality. These function preceed with "RE" in front of the function name (eg REFind). For those unfamiliar to regular expressions, these functions allow you to provide regular expression patterns against a provided string to help find, replace, etc complex strings.
Now I would think for most of us ColdFusion programmers we don't look any further than to use these provided functions, BUT there does come a time when you could hit a limitation on how ColdFusion interacts with the regular expression engine (eg. cannot do negative/positive look behinds). To get around this you need to work with the underlying engine itself provided in Java.
To do this you only need to do the following adjustments when running against regular expression functions:
ColdFusion example:
REReplace(strString,"for\s?\(","","all")
Underlying Java example:
strString.ReplaceAll("for\s?\(","")
It's pretty much that simple. You don't need to do a cfobject to the library or any other setup to use this feature as the string object in ColdFusion already has access to such functionality when it is initially created.
Below is a link to the matcher java class reference, which contains other possible underlying methods. I say "possible" because I have not tested them myself yet.
http://java.sun.com/docs/books/tutorial/essential/regex/
NOTE: I have tested this type of approach in a ColdFusion 6.1 environment and it works.
4-13-2008
4-13-2008
4-13-2008
4-11-2008
4-11-2008