Regex 是否可以在VTL解析器内执行基于正则表达式的字符串替换?
我想定义一个响应映射模板,如下所示:Regex 是否可以在VTL解析器内执行基于正则表达式的字符串替换?,regex,velocity,aws-appsync,vtl,Regex,Velocity,Aws Appsync,Vtl,我想定义一个响应映射模板,如下所示: #set( $postIds = [] ) #foreach( $item in $ctx.result.items ) #if( !$util.isNull($item)) $util.qr($postIds.add($item.SK.replace("^([0-9]){1,}-", ""))) #end #end { "items": $utils.toJson($postIds), #if( ${con
#set( $postIds = [] )
#foreach( $item in $ctx.result.items )
#if( !$util.isNull($item))
$util.qr($postIds.add($item.SK.replace("^([0-9]){1,}-", "")))
#end
#end
{
"items": $utils.toJson($postIds),
#if( ${context.result.nextToken} )
"nextToken": "${context.result.nextToken}",
#end
}
目标是删除每个项的SK属性开头的时间戳和“-”字符
我检查了正则表达式是否正确,但这似乎不起作用,因为开头的数字没有删除
还尝试使用…replace(/^([0-9]){1,}-/“,”)
如果我记得正确的话,文档中说所有的Java字符串方法都是可用的
我在这里做错了什么?要替换正则表达式,请使用 将此字符串中与给定正则表达式匹配的每个子字符串替换为给定替换 或
replaceFirst
确保
SK
是字符串或使用toString()
替换正则表达式使用
将此字符串中与给定正则表达式匹配的每个子字符串替换为给定替换
或replaceFirst
确保SK
是字符串或使用toString()