Plucka
asked on
ReReplace Last Occurance
Can I use ReReplace to replace the last occurance of a pattern with something else.
ie: I want to replace the last occurance of a space with a <br>
The Quick Brown Fox
I want to become
The Quick Brown<br>Fox
which would also work for 1 occurance.
Hello There
becomes
Hello<br>There
ie: I want to replace the last occurance of a space with a <br>
The Quick Brown Fox
I want to become
The Quick Brown<br>Fox
which would also work for 1 occurance.
Hello There
becomes
Hello<br>There
i know u have specifically asked for replacenocase
but just have a look at this
<CFSET var = "The Quick Brown Fox">
<CFSET x = ListGetAt(var,listlen(var, ' '),' ')>
<CFSET var = ListDeleteAt(var,listlen(v ar,' '),' ') & "<br>" & x>
<CFOUTPUT>#var#</CFOUTPUT>
Regards
Hart
but just have a look at this
<CFSET var = "The Quick Brown Fox">
<CFSET x = ListGetAt(var,listlen(var,
<CFSET var = ListDeleteAt(var,listlen(v
<CFOUTPUT>#var#</CFOUTPUT>
Regards
Hart
ASKER
That's probably only marginally easier to read code than my
#Reverse(Replace(Reverse(t est)," ",Reverse("<br>")))#
I sometimes show this line of code to potential employees and ask them to tell me what it's doing.
I think there's probably a simple regular expression for this, but i'm not that good at regular expressions.
PS: I specifically asked for REreplace not replacenocase.
PPS: Wouldn't it be nice if Replace had a Scope option of last.
#Reverse(Replace(Reverse(t
I sometimes show this line of code to potential employees and ask them to tell me what it's doing.
I think there's probably a simple regular expression for this, but i'm not that good at regular expressions.
PS: I specifically asked for REreplace not replacenocase.
PPS: Wouldn't it be nice if Replace had a Scope option of last.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi again,
one addition:
instead of reReplaceNoCase() you can use reReplace and change the regex to "([a-zA-Z0-9[:punct:]]+)$" , but, I think the case insensitive comparison is a bit faster...
Chris
one addition:
instead of reReplaceNoCase() you can use reReplace and change the regex to "([a-zA-Z0-9[:punct:]]+)$"
Chris
ASKER
Thanks, that worked a treat, thought there would be a regex method.
You're welcome. :-)
ASKER
#Reverse(Replace(Reverse(t
Which works fine, just makes for some unreadable code, thought there might be a simple regular expression method.
PS: I also know how to do this through loops and finds, but I'm after a single statement like above but simpler.