我需要一些正则表达式,它将返回第一个反斜杠和第五个反斜杠之间的值,在下面用粗体突出显示:
dataCapture/22E6F953EA6D445C8FB20E9D29A977D7/6.20.0-3c1e4b0c459eb93e43eb64fed7447a41fb4d4029/uuid_2b896c17-eb5c-4fd1-ae44-78dcda6c8ee9/36/3D1C3A58A039103375D320E524500A74
到目前为止,我只能想出一个regex来返回数据,直到第一个反斜杠:
\/dataCapture\/(.+?)\/如何将上述内容扩展到包含第五个反斜杠的数据?
发布于 2020-08-01 02:56:50
也许并不是最干净的,但这就是完成工作的原因:
const regex = /dataCapture\/([a-zA-Z0-9]+\/[a-zA-Z0-9\.\-]+\/[a-zA-Z0-9\.\-\_]+\/[0-9]+)\/.*/;
const value = "dataCapture/22E6F953EA6D445C8FB20E9D29A977D7/6.20.0-3c1e4b0c459eb93e43eb64fed7447a41fb4d4029/uuid_2b896c17-eb5c-4fd1-ae44-78dcda6c8ee9/36/3D1C3A58A039103375D320E524500A74";
console.log(value.match(regex)[1]); // => 22E6F953EA6D445C8FB20E9D29A977D7/6.20.0-3c1e4b0c459eb93e43eb64fed7447a41fb4d4029/uuid_2b896c17-eb5c-4fd1-ae44-78dcda6c8ee9/36
发布于 2020-08-01 02:57:28
发布于 2020-08-01 05:21:38
我不熟悉JMeter,但我知道它使用了Perl5 5正则表达式的一个细微的变体,所以我希望匹配下面的正则表达式将提取出感兴趣的字符串。
(?<=^dataCapture\/)(?:[^\/]*\/){3}[^\/]*(?=\/)regex引擎执行以下操作。
(?<= : begin positive lookbehind
^ : match beginning of string
dataCapture\/ : match 'dataCapture\/
) : end positive lookbehind
(?:[^\/]*\/) : match 0+ charsother than '/', followed by '/', in
a non-capture group
{3} : execute the non-capture group 3 times
[^\/]* : match 0+ chars other than '/'
(?=\/) : positive lookahead asserts that the next char is '/'https://stackoverflow.com/questions/63201222
复制相似问题