|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
\1 and 000I need to change a string like the following:
"house in clapham 200K with garden" into "house in clapham 200000 with garden" So replacing the "K" with "000". I came up with: (\d*?)K But then in trying to replace the match with: \1000 Or \1 and three zeros, it falls foul because it's looking for the 1000th sub expression. Trying to escape the first zero doesn't work because \0 returns the whole matched expression. Any ideas? I can do two operations on it and be done but I'd like to know if there's something I'm missing. Ta. Adrian ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1128 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
|
|
Re: \1 and 000On Mon, Mar 10, 2008 at 8:26 AM, Adrian Lynch <contact@...> wrote:
> I need to change a string like the following: > > "house in clapham 200K with garden" > > into > > "house in clapham 200000 with garden" > > So replacing the "K" with "000". > > I came up with: > > (\d*?)K > > But then in trying to replace the match with: > > \1000 > > Or \1 and three zeros, it falls foul because it's looking for the 1000th sub > expression. > > Trying to escape the first zero doesn't work because \0 returns the whole > matched expression. Try using the concatentation operator: replace ( (\d+)K, '\1' & '000' ) BTW, I didn't look up the replace() function signature, so treat that as pseudo-code. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1129 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
|
|
RE: \1 and 000Cheers. I thought of that. It still acts as the one string.
There must be way to have a back reference next to a number string surely? Adrian -----Original Message----- From: Rob Wilkerson [mailto:rob@...] Sent: 10 March 2008 12:33 To: RegEx Subject: Re: \1 and 000 On Mon, Mar 10, 2008 at 8:26 AM, Adrian Lynch <contact@...> wrote: *snip* Try using the concatentation operator: replace ( (\d+)K, '\1' & '000' ) BTW, I didn't look up the replace() function signature, so treat that as pseudo-code. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1130 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
|
|
Re: \1 and 000On Mon, Mar 10, 2008 at 9:11 AM, Adrian Lynch <contact@...> wrote:
> Cheers. I thought of that. It still acts as the one string. > > There must be way to have a back reference next to a number string surely? I'm sure your right. In PHP, you can do it as \{1}, but I don't recall ever needed to do such a thing with ColdFusion (which I assume you're using?). At the risk of being obvious, I assume you've tried "\\1"? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1131 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
|
|
RE: \1 and 000Yup, tried a bunch of variations on that. Yup, it's CF. \(1) doesn't work.
Hmmmmm. Adrian -----Original Message----- From: Rob Wilkerson Sent: 10 March 2008 13:20 To: RegEx Subject: Re: \1 and 000 On Mon, Mar 10, 2008 at 9:11 AM, Adrian Lynch <contact@...> wrote: > Cheers. I thought of that. It still acts as the one string. > > There must be way to have a back reference next to a number string surely? I'm sure your right. In PHP, you can do it as \{1}, but I don't recall ever needed to do such a thing with ColdFusion (which I assume you're using?). At the risk of being obvious, I assume you've tried "\\1"? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1132 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
|
|
Re: \1 and 000On Mon, Mar 10, 2008 at 9:30 AM, Adrian Lynch <contact@...> wrote:
> Yup, tried a bunch of variations on that. Yup, it's CF. \(1) doesn't work. > Hmmmmm. Did you try "\\\1"? That will work in PHP, as well. Of course, now I'm just throwing stuff out there semi-blindly. :-) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1133 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
|
|
Re: \1 and 000Shouldn't you be writing "200,000" (or "200 000") anyway?
So use "\1,000" (or "\1 000")? Alternatively, use Java regex so you can do lookbehinds, to effectively just replace K with 000. ie: <cfset Text = JREReplace(Text,'(?<=[0-9]+)K','000','ALL')/> (You can get the JREReplace udf from Ben Nadel's site) On Mon, Mar 10, 2008 at 12:26 PM, Adrian Lynch <contact@...> wrote: > I need to change a string like the following: > > "house in clapham 200K with garden" > > into > > "house in clapham 200000 with garden" > > So replacing the "K" with "000". > > I came up with: > > (\d*?)K > > But then in trying to replace the match with: > > \1000 > > Or \1 and three zeros, it falls foul because it's looking for the 1000th > sub > expression. > > Trying to escape the first zero doesn't work because \0 returns the whole > matched expression. > > Any ideas? > > I can do two operations on it and be done but I'd like to know if there's > something I'm missing. > > Ta. > > Adrian > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1134 Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21 |
| Free embeddable forum powered by Nabble | Forum Help |