You can use $ to match the end of the string, and [^,] to match
"anything except a comma".

So to find the last comma, you want to match a comma, followed by
"anything except a comma" as many times as necessary until the end of
the string.

To then replace the comma, but not the non-comma text afterwards, we
can use a lookahead - using syntax (?=X) to say "make sure X matches
the following text, but don't include it in the match/replacement.

Putting all that together, the regex would be:
,(?=[^,]+$)

And that can be used with:
<cfset Text = REReplace( Text , ',(?=[^,]+$)' , ' and' ) />


Hopefully that all makes sense?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1255
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/regex/unsubscribe.cfm

Reply via email to