Jmeter正则表达式可变行数 [英] Jmeter regex variable number of lines

查看:135
本文介绍了Jmeter正则表达式可变行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,如何编写Jmeter正则表达式,以便与解析的文本中的多少行无关紧要?例如,正则表达式:

My question is, how can a Jmeter regular expression be written so that it does not matter how many lines are in the parsed text? For example, the Regular Expression:

<FMSFlightPlan>\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)</FMSFlightPlan>

将匹配下面显示的7行字符串,并返回两个标签之间的所有内容

will match the 7 line string shown below and return everything between the two tags

<FMSFlightPlan>
8725
AN NTEST/GL 
- FPN/FN/RP:DA:GCRR:AA:LEMD:F:KORAL,N29439W012347.UG5. 
SONSO,N30007W012061.UN871.VJF,N36144W005585.UN10. 
HIJ,N38305W005060.Z230.SOTUK,N39116W004448 
</FMSFlightPlan>

但是,相同的正则表达式将为以下6行字符串返回一个NA:

However, the same regular expression will return an NA for the following 6 line string:

<FMSFlightPlan>
C90D
AN N9696T/GL 
- FPN/FN/RP:DA:KDEN:AA:KSFO:F:DBL,N39264W106537.J80. 
ILC,N38150W114237..RUMPS,N38072W117163..OAL,N38002W117462 
</FMSFlightPlan>

我知道也必须为正确的行数设置模板,我不认为这是问题的原因.

I understand that Template must be set for the correct number of lines as well, I don't believe this is the cause of the problem.

推荐答案

原来,我需要建立dotall模式,该模式基本上告诉正则表达式提取器将新行解析为空白.通过在正则表达式的开头添加标签(?s)来建立dotall模式,如下所示:

It turned out that I needed to establish dotall mode, which basically tells the regular expression extractor to parse new lines as if they were whitespace. dotall mode is established by adding the tag (?s) to the very beginning of the regular expression like so:

(?s)<FMSFlightPlan>(.*?)</FMSFlightPlan>

但是,我仍然无法打印匹配的文本.由于某种原因,我正在使用的Beanshell断言无法将正则表达式引用名称"识别为变量,并给我错误消息:

However... I still haven't been able to print the matched text. For some reason the Beanshell Assertion I'm using doesn't recognize the regular expression Reference Name as a variable and gives me the error message:

断言错误:true 断言失败:错误 断言失败消息:org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval源文件:内联评估:``import java.io. *; //将数据结果写到文件outfile ="/Users/Dani.."令牌解析错误:第12行,第380列出现词法错误.遇到:"\ n"(10),后跟:"\" 3811 \ tYes \ tAAR \ tSTN \ t835 \ t \ t $ B738 \ tfp,nradps,art,CCAAN,EXCD,wp00,p00 \ t37919 \ ta0 \ ti \ t10 \ t0 \ t3 \ t0 \ t \ t14 \ t 25 /M \ t0000ADF \ t140785 \ t133806 \ t006979 \ t01:15:00 \ t0484 \ t360 \ t0379 \ t360 \ t0112 \ t 000932 \ tP00 \ t007115 \ t2013-02-13T21:23:00Z \ t2013-02-14T08: 35:00 + 00:00 \ t000837 \ t00:10:00 \ t000000 \ t00:00:00 \ t000837 \ t00:10:00 \ t000000 \ t000000 \ t000000 \ t00:00:00 \ t000000 \ t00:00: 00 \ t"

Assertion error: true Assertion failure: false Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.io.*; //write out the data results to a file outfile = "/Users/Dani . . . '' Token Parsing Error: Lexical error at line 12, column 380. Encountered: "\n" (10), after : "\"3811\tYes\tAAR\tSTN\t835\t\t$B738\tfp,nradps,art,CCAAN,EXCD,wp00,p00\t37919\ta0\ti\t10\t0\t3\t0\t \t14\t 25/M\t0000ADF\t140785\t133806\t006979\t01:15:00\t0484\t360\t0379\t360\t0112\t 000932\tP00 \t007115\t2013-02-13T21:23:00Z\t2013-02-14T08:35:00+00:00\t000837\t00:10:00\t000000\t00:00:00\t000837\t00:10:00\t000000\t000000\t000000\t00:00:00\t000000\t00:00:00\t"

我目前正在尝试使用用户定义的变量来确保Beanshell断言可以识别正则表达式.

I'm currently attempting to use a User Defined Variable to ensure the regular expression is recognized by the Beanshell Assertion.

感谢大家的回应!

这篇关于Jmeter正则表达式可变行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆