• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

backreference with ReReplace

Guest
Nov 19, 2007 Nov 19, 2007

Copy link to clipboard

Copied

I'm hung up on something I thought would be fairly simple. I want to add a zero to the end of a string of digits using ReReplace. But the zero needs to be escaped as otherwise CF interprets it as part of the backreference. To boil it down to the bare bones (actually part of something a lot more complex):
REReplace("123","([0-9]{3})", "\10")
returns empty string as CF thinks it's 10 instead of 1
REReplace("123","([0-9]{3})", "\1\0")
returns 123123 for reasons I'm not certain but maybe CF sees \0 as equivalent to \1
REReplace("123","([0-9]{3})", "\1\\0")
returns 123\0

I've tried everything else I can think of with no success. ANy help appreciated.

Thanks,
Ken
TOPICS
Advanced techniques

Views

308

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Nov 19, 2007 Nov 19, 2007
Use \E to separate them e.g. REReplace("123","([0-9]{3})", "\1\E0")

\E is usually used when ending a case change (see http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000989.htm) however as it has no output it will solve your problem.

HTH

Votes

Translate

Translate
Engaged ,
Nov 19, 2007 Nov 19, 2007

Copy link to clipboard

Copied

Use \E to separate them e.g. REReplace("123","([0-9]{3})", "\1\E0")

\E is usually used when ending a case change (see http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFu... however as it has no output it will solve your problem.

HTH

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 20, 2007 Nov 20, 2007

Copy link to clipboard

Copied

LATEST
Great solution! Wish I'd thought of that.

Thanks,
Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation