Non sono mai stato felice con l'espressione regolare funzioni corrispondenti in CF. Quindi, ho scritto il mio:
<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 [];} //handle no match at all
for(i=1; i<= arrayLen(sucky.len); i++){
//if there's a match with pos 0 & length 0, that means the mime type was not specified
if (sucky.len[i] gt 0 && sucky.pos[i] gt 0){
//don't include the group that matches the entire pattern
var matchBody = mid(data, sucky.pos[i], sucky.len[i]);
if (matchBody neq arguments.data){
arrayAppend(awesome, matchBody);
}
}
}
return awesome;
}
</cfscript>
Applicato al tuo problema, qui è il mio esempio:
<cfset origString = "joe smith <[email protected]>" />
<cfset regex = "<([^>]+)>" />
<cfset matches = reFindNoSuck(regex, origString) />
Dumping la "corrisponde" variabile dimostra che si tratta di un array con 2 elementi. Il primo sarà <[email protected]>
(perché corrisponde all'intera espressione regolare) e il secondo sarà [email protected]
(poiché corrisponde al primo gruppo definito nell'espressione regolare - tutti i gruppi successivi verranno acquisiti e inclusi nell'array).
fonte
2010-06-15 15:57:43
Che ne dici di dirci cosa hai provato e non ha funzionato? È più facile andare da lì ... – jhwist