0

My task is to find everything inside a curly bracket using coldfusion.

So for example if the string is like this - "Approval request from {user_first_name} {user_last_name} of {user_company}"

then I should be able to get back {user_first_name},{user_last_name} and {user_company}.

I tried doing it using reMatch and some regular expressions I found online but they did not work.

Anyone has any idea?

P.S: I tried the regular expressions given here - Regex to get string between curly braces "{I want what's between the curly braces}" but that returned an empty string.

Community
  • 1
  • 1
nasaa
  • 2,701
  • 8
  • 47
  • 76

1 Answers1

4

Here's what seems to work for me:

<cfscript>
input="Approval request from {user_first_name} {user_last_name} of {user_company} {}";
pattern="{[^}]*}"; //allowing for empty brackets
pattern="{[^}]+}"; //not allowing empty brackets

matches=rematch(pattern,input);
for (i=1;i<=arraylen(matches);i++){
    WriteOutput(matches[i]);
    WriteOutput("<br />");
}
</cfscript>

Without a code sample, I can't see what was going wrong, but this works on CF 9.0.1, hope that helps

barnyr
  • 5,678
  • 21
  • 28