0

我的任务是使用冷融合找到大括号内的所有内容。

例如,如果字符串是这样的 - “来自 {user_first_name} {user_last_name} of {user_company} 的批准请求”

那么我应该能够取回 {user_first_name}、{user_last_name} 和 {user_company}。

我尝试使用 reMatch 和我在网上找到的一些正则表达式来做到这一点,但它们不起作用。

有人有什么想法吗?

PS:我尝试了这里给出的正则表达式 - 正则表达式在大括号之间获取字符串“{我想要大括号之间的内容}”但是返回了一个空字符串。

4

1 回答 1

4

这似乎对我有用:

<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>

没有代码示例,我看不出出了什么问题,但这适用于 CF 9.0.1,希望对您有所帮助

于 2012-05-14T15:33:07.467 回答