chrismead Posted April 18, 2017 Share Posted April 18, 2017 I've run into a snag with a template where users are allowed to enter their own comment line. Some people requested Smilies in the form of ":)" which I used a snippet of code to replace with ☺: return Trim(Field("Comment").replace(":)","☺"); Someone just asked for a line of Smilies ":) :) :)" and that code returned "☺ :) :)". No problem, I'm thinking, I'll just make it a global replace with /g: return Trim(Field("Comment").replace(/:)/g,'☺'); Unfortunately, the close parenthesis refuses to register as a character in this format- an error message is returned when I try to validate: "Comment Rule, line 6: SyntaxError: unmatched ) in regular expression" Using .replace(":)"/g,'☺') doesn't work because the expressions are mixed (I'm not sure if that's the right terminology). Using .replace(/:()/g,'☺') generates valid code, but returns ☺)☺)☺)☺) (I did not expect it to give the right results, but it shows some of the internal process being applied). I'm not at the end of my rope, but some of the solutions I'm thinking of are getting really complicated. Does anyone have suggestions? Quote Link to comment Share on other sites More sharing options...
step Posted April 18, 2017 Share Posted April 18, 2017 Parentheses have special meaning in regular expressions. You need to escape them (and close the 'Trim' function): return Trim(Field("Comment")[color="red"])[/color].replace(/:[color="Red"]\[/color])/g,'☺'); Quote Link to comment Share on other sites More sharing options...
chrismead Posted April 18, 2017 Author Share Posted April 18, 2017 That is the magic! Thank you! :) :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.