CFLib.org – Common Function Library Project

REReplaceList(str, oldList, newList)

Last updated May 17, 2007

author

Tuyen Tran

Version: 1 | Requires: CF5 | Library: StrLib

Description:
RE replace a list list of regular expression with a list of string.

Return Values:
Returns a string.

Example:

Convert HTML to XML:
<cfsavecontent variable="thisComment">
<table border="0">
<tr height="17">
	<td width="68" height="17">RE Replace List</td>
	<td width="49">HTML to XML (part 1)</td>
</tr>
</table>
</cfsavecontent>

<cfscript>
thisComment = REReplaceList(thisComment, "<table[^>]*>,<tr[^>]*>,<td[^>]*>,</td>,</tr>,</table>", "<XmlRool>,<Row>,<Cell>,</Cell>,</Row>,</XmlRoot>");
</cfscript>
<cfoutput>#htmlCodeFormat(thisComment)#</cfoutput>

Parameters:

Name Description Required
str String to parse. Yes
oldList List of regular expressions. Yes
newList List of replacements. Yes

Full UDF Source:

/**
 * RE replace a list list of regular expression with a list of string.
 * 
 * @param str 	 String to parse. (Required)
 * @param oldList 	 List of regular expressions. (Required)
 * @param newList 	 List of replacements. (Required)
 * @return Returns a string. 
 * @author Tuyen Tran (tuyen.k.tran@gmail.com) 
 * @version 1, May 17, 2007 
 */
function REReplaceList(str, oldList, newList) {
	var i = 1;
	for (i=1; i lte listLen(oldlist); i=i+1) {
		str = REReplace(str, listGetAt(oldList, i), listGetAt(newList, i), "all");
	}
	return str;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson