Skip to main content
Inspiring
January 22, 2009
Question

Regular Expressions

  • January 22, 2009
  • 4 replies
  • 526 views
I'm trying to take out surrounding quotes and 1000s seperators from numbers 0 to just under one trillion. In DW I can search for
,"\$(\d*),(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*.\d*)"|,\$(\d*.\d*)
and replace it with
,$1$2$3$4$5$6$7$8$9$10
no problem, but when I try
rereplace(my_cell,',"\$(\d*),(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*.\d*)"|,\$(\d*.\d*)', ',$1$2$3$4$5$6$7$8$9$10','ALL') in CF8 I get output like:
A0B36,$1$2$3$4$5$6$7$8$9$10
A0B45, $612,702.31
which is clearly incorrect. I am new at regular expressions, but if it's working in DW, I suspect I'm messing up the function somehow. Please help!
    This topic has been closed for replies.

    4 replies

    kodemonkiAuthor
    Inspiring
    January 22, 2009
    You're right. http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=regexp_10.html is a good start. The documentation I read was here: http://www.adobe.com/devnet/dreamweaver/articles/regular_expressions_07.html admittedly for DW, not CF.
    I can't replace all the commas because it's a .csv file. Actually, I'm not entirely sure that's what [",] means. Excel surrounds fields having commas in them with double quotes, so I'm trying to pull out the commas as well as the quotes.
    That and I thought it'd be good practice.
    Inspiring
    January 22, 2009
    On Thu, 22 Jan 2009 17:34:02 +0000 (UTC), kodemonki wrote:

    > I'm trying to take out surrounding quotes and 1000s seperators from numbers 0
    > to just under one trillion. In DW I can search for
    >
    > ,"\$(\d*),(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*.\d*)"

    Why don't you just use [",] as your match string, and replace it with ""?
    Or am I misreading your requirements here?

    Regarding your original problem... did it occur to you to read the docs?
    http://livedocs.adobe.com/coldfusion/8/regexp_01.html

    When stuck... RTFM is always a really good place to start.

    --
    Adam
    kodemonkiAuthor
    Inspiring
    January 22, 2009
    That works much better, thank you!
    Inspiring
    January 22, 2009
    Try matching your expressions in the replace string using a "\" instead of a "$":

    rereplace(my_cell,',"\$(\d*),(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*),(\d*.\d*)"|,"\$(\d*),(\d*.\d*)"|,\$(\d*.\d*)', ',\1\2\3\4\5\6\7\8\9\10','ALL')