In coldfusion is there a function which takes a regular expression and a string and return a sub-string...?
As a string? No. But take a look at the regex functions in the String functions category. - ReFind/NoCase - ReReplace/NoCase - ReMatch/NoCase http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_18.html#1099887
This is a working example of what you are looking for. I suggest if you do regex matches, wrap the code around a catch/try if there is no match. <cfscript> content = 'The quick brown fox jumped over the lazy dogs.'; regExp = '(fox)'; //Trim the string just in case there are spaces to throw off the position count trimDoc = trim(content); //This if there is a match, it returns an array with position(pos) and length(length) result = REfindNoCase(regExp,trimDoc,1,"Yes"); //Save the match to a query based on the position and length of the match matchedString = mid(trimDoc,result.pos[2],result.len[2]); </cfscript> <cfoutput> #matchedString# </cfoutput>