Regular Expressions in JMeter
上一篇 / 下一篇 2012-03-18 10:20:46 / 个人分类:JMeter
文章来源
- 文章来源:【转载】
JMeter includes the pattern matching software Apache Jakarta ORO.51Testing软件测试网 rX9w#C&s
There is some documentation for this on the Jakarta web-site.51Testing软件测试网zI U6L.Z r8G+[%S
A summary of the pattern matching characters can be found at http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html51Testing软件测试网5uoFD8iz }
There is also documentation on an older incarnation of the product at OROMatcher User's guide, which might prove useful.
,kc/rkcD\051Testing软件测试网6Hw1{\K$^DJ.Q
51Testing软件测试网 w(z*VuA+E*J(}
Overview
The pattern matching is very similar to the pattern matching in Perl. A full installation of Perl will include plenty of documentation on regular expressions - look for perlrequick, perlretut, perlre, perlreref. O'Reilly sell a book called "Mastering Regular Expressions" by Jeffrey Friedl which will tell you all you need to know (and a lot more) about regular expressions.
)MQ;e$w e4c8A0There are also a couple of sample chapters available on their web-site covering REs in Java and .NET, and the Java chapter has a section on ORO (PDF)- worth a look.51Testing软件测试网R:`5M?4l+`
It is worth stressing the difference between "contains" and "matches", as used on the Response Assertion test element:
$t` Pd4Rn8P-Yn;^p0p0"contains" means that the regular expression matched at least some part of the target, so 'alphabet' "contains" 'ph.b.' because the regular expression matches the substring 'phabe'.51Testing软件测试网:nL0e8F;nD`zj
"matches" means that the regular expression matched the whole target. So 'alphabet' is "matched" by 'al.*t'. In this case, it is equivalent to wrapping the regular expression in ^ and $, viz '^al.*t$'. However, this is not always the case. For example, the regular expression 'alp|.lp.*' is "contained" in 'alphabet', but does not match 'alphabet'.
Lp3?3d[s0
Why? Because when the pattern matcher finds the sequence 'alp' in 'alphabet', it stops trying any other combinations - and 'alp' is not the same as 'alphabet', as it does not include 'habet'.51Testing软件测试网4^6N#_!CeY$w
Note: unlike Perl, there is no need to (i.e. do not) enclose the regular expression in //. So how does one use the Perl modifiers ismx etc if there is no trailing /? The solution is to use Perl5 extended regular expressions, i.e. /abc/i becomes (?i)abc