如何在空手道中将#string 设置为具有相同正则表达式的值

How to set #string into value having the same regex in karate

我正在尝试将#string 设置为在空手道中具有相同正则表达式的值,如下所示: 我有 sampleXML:

<Addresses>
    <Address Id="AD1">
       <StreetNum>0001</StreetNum>                   
    </Address>
    <Address Id="BR9">
       <StreetNum>0002</StreetNum>                   
    </Address>
    ...
</Addresses>

从上面的xml例子中,我将#string设置为具有相同正则表达式的值,如下所示:

* string temp = sampleXML
* xml report = temp.replaceAll('<Address Id="#regex [A-Z0-9]{3}">', '<Address Id="#string">')

但是它不起作用,所以如果您知道如何在空手道中将#string 设置为具有相同正则表达式的值,请帮助我?谢谢!

我的预期结果为:

<Addresses>
        <Address Id="#string">
           <StreetNum>0001</StreetNum>                   
        </Address>
        <Address Id="#string">
           <StreetNum>0002</StreetNum>                   
        </Address>
        ...
 </Addresses>

这比我想象的要棘手,你必须在 Java脚本中使用正则表达式:

* text payload =
"""
<Addresses>
    <Address Id="AD1">
       <StreetNum>0001</StreetNum>                   
    </Address>
    <Address Id="BR9">
       <StreetNum>0002</StreetNum>                   
    </Address>
</Addresses>
"""
* def temp = payload.replaceAll(/Id="[^"]+"/g, 'Id="#string"')
* print temp

对于更高级的需求,您还可以选择调用 Java 代码:https://github.com/karatelabs/karate#calling-java