Copy link to clipboard
Copied
Please find the below sample code,
Copy link to clipboard
Copied
# is reserved for variable use in CF. To use it in a regular expression in a function like you are, I believe you need to use a double-hash: ## So,
newStr = str.replace(/[&##]/g, "" );
Copy link to clipboard
Copied
Thanks for replying, it doesn't seem to be working. Is there any other way we can solve this?
And can you please let me know what is \.\- in the below line of code ,
Copy link to clipboard
Copied
I'm sory it works thank you!
Copy link to clipboard
Copied
Vishnu, you have a couple of problems there. First the compilation error is because you're passing in as the first argument some characters (the regex) that form a string--and a string in cfml must be enclosed in quotes.
More important, though, the cfml replace expression doesn't work with regular expressions. (Did you find some resource suggesting it would? Where is it?)
Instead, consider the rereplace and rereplacenocase functions. See the docs starting at https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-m-r/replace.html. See especially the first example, which you can also run online at the Cffiddle site. Then see still more on the topic at https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/using-regul...
Let us know how things go.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more