I have never been happy with regex features in CF. Therefore, I wrote my own:
<cfscript> function reFindNoSuck(string pattern, string data, numeric startPos = 1){ var sucky = refindNoCase(pattern, data, startPos, true); var i = 0; var awesome = []; if (not isArray(sucky.len) or arrayLen(sucky.len) eq 0){return [];}
As applied to your problem, here is my example:
<cfset origString = "joe smith < joesmith@domain.com >" /> <cfset regex = "<([^>]+)>" /> <cfset matches = reFindNoSuck(regex, origString) />
Dropping the variable "matches" indicates that it is an array with two elements. The first will be < joesmith@domain.com > (because it matches the entire regular expression), and the second will be joesmith@domain.com (since it matches the first group defined in the regular expression, all subsequent groups will also be captured and included in the array).
Adam tuttle
source share