Skip to main content
Participant
April 26, 2011
Question

ReplaceList

  • April 26, 2011
  • 1 reply
  • 353 views

I have used ReplaceList() to replace values in one list with other values, but what I need is a REReplaceList() that would replace all the values in a list with a regex. Any ideas how I'd do this? The only thing I can think of is doing a loop. Here's the code to put in "hey" every three characters into every word in the list #mylist# using a loop.

<cfloop list="#mylist#" index="x">

<cfset mynewword = reReplaceNoCase(#x#, "(.{3})", "\1hey", "all")>

<cfset NewList = ReplaceNoCase(#NewList#, "#x#", "#mynewword#")>

</cfloop>

But if ReReplaceList existed, couldn't I just do this?:

<cfset mynewlist = REReplaceList("#list#", "(.{3})", "\1hey", "all")>

This topic has been closed for replies.

1 reply

Inspiring
July 14, 2011

I would think that if you define your pattern to exclude commas and spaces you could accomplish the same thing using a pattern like:

([^, ]{3})

that is - match every character that is not a comma or space in 3 character sets

e.g.

#ReReplace(mylist, "([^, ]{3})", "\1hey", "all")#