Skip to main content
Inspiring
June 13, 2008
Question

What does this mean ?

  • June 13, 2008
  • 2 replies
  • 635 views
I was provided this code and I have no idea what it does.

<cfset Form.supplier_email = reReplace(Form.supplier_email,",+$","","ALL") />

I was told that it is supposed to concatenate emails together, separated by a comma. But if the email contains a space, the entire application blows up.

Does this statement check for spaces ?
    This topic has been closed for replies.

    2 replies

    Participating Frequently
    June 13, 2008
    What error message(s) are you getting specifically?
    Participating Frequently
    June 13, 2008
    I can't imagine why that particular line of code would be the source of your problem.
    In plain english, all that regular expression replacement should be doing is:

    quote:


    Remove one or more consecutive commas that occur at the end of the string found in variable "Form.supplier_email"



    For example, if "Form.supplier_email" contained the string:
    test1@email.com,test2@email.com,test3@email.com,,,,,,,,

    You would end up with:
    test1@email.com,test2@email.com,test3@email.com

    That only part of that expression that I find questionable is the "ALL" (argument 4) - that shouldn't be necessary in this case. That presence of that 4th argument shouldn't cause the issue you describe though - it should just do nothing in this case.
    trojnfnAuthor
    Inspiring
    June 13, 2008
    ok, so that is all it does, reomove the commas at the end ?

    It seems to work great and it concatenates all the emails into one string for cfmail output, in the format "john_doe@mail.com,janesmith@abc.com" etc.

    But the problem is if they enter an email address like jane doe. The string output then becomes "john_doe@mail.com,jane doe" and it blows up. I never ran into this problem before and since I did not understand what the code meant, I asumed it did an edit for invalid addresses, but it does not.

    Is is possible to check the string for invalid entries ?
    Participating Frequently
    June 13, 2008
    quote:

    I did not understand what the code meant, I asumed it did an edit for invalid addresses, but it does not.
    I guess that this is the primary difference between writing code, and actually understanding it. Doing a little research on regular expressions, and how the REReplace() function uses them, would work wonders with you actually being able to figure this out for yourself.

    Phil