我是Jmeter的新手,想创建一个可以捕获以下两个URL的正则表达式:
我正在尝试使用以下表达式:
movies/(.+?)/(.+?)&
这两个网址都不起作用:
https://in.bookmyshow.com/bengaluru/movies/avengers-endgame/ET00090482&
https://in.bookmyshow.com/movies/the-tashkent-files/ET00069063/&
答案 0 :(得分:0)
我猜测我们可能会传递一个域并在此处捕获URL的一些组成部分,例如ID。让我们从具有更多边界的表达式开始,然后将它们删除(如果不希望出现的话):
(.+?)(in.bookmyshow.com)\/(.+?)\/([A-Z0-9]+)(.*&)
如果不需要此表达式,可以在regex101.com中对其进行修改或更改。
jex.im还有助于可视化表达式。
此代码段只是为了说明捕获组的工作方式:
const regex = /(.+?)(in.bookmyshow.com)\/(.+?)\/([A-Z0-9]+)(.*&)/gm;
const str = `https://in.bookmyshow.com/bengaluru/movies/avengers-endgame/ET00090482&
https://in.bookmyshow.com/movies/the-tashkent-files/ET00069063/&`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
如果我们希望传递包含movies
的URL并在没有URL的情况下使它们失败,则可以在初始表达式中添加新的边界:
(.+?)(in.bookmyshow.com)\/(.+)?movies(.+)?\/([A-Z0-9]+)(.*&)
const regex = /(.+?)(in.bookmyshow.com)\/(.+)?movies(.+)?\/([A-Z0-9]+)(.*&)/gm;
const str = `https://in.bookmyshow.com/bengaluru/movies/avengers-endgame/ET00090482&
https://in.bookmyshow.com/movies/the-tashkent-files/ET00069063/&
https://in.bookmyshow.com/music/the-tashkent-files/ET00069063/&
https://in.bookmyshow.com/bengaluru/music/the-tashkent-files/ET00069063/&`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
答案 1 :(得分:0)
我无法发表评论,但想补充Emma发表的内容。
一旦获得所需的分组,JMeter中就会有一个“匹配编号”字段。如果您输入
refName_n_g<group number>
它应该返回您想要的作品。因此,如果正则表达式中的电影标题为第2组,则应放置
refName_n_g2
这是有关JMeter和正则表达式的页面:
Using-RegEx-Regular-Expression-Extractor-with-JMeter
编辑: 使用
movies\/(.+?\/.+?)&
您的第1组会给您“ avengers-endgame / ET00090482”
答案 2 :(得分:0)
您的表情:电影/(.+?)/(.+?)& amp
由于您搜索了两个组:电影名称(avengers-endgame)和ID(ET00090482),因此需要在JMeter的正则表达式提取器中将模板设为$ 1 $$ 2 $ 。
此外,请检查以下部分-适用于和要检查的字段,以根据要求进行选择
参考:
答案 3 :(得分:0)