Google News
logo
JMeter - Interview Questions
Explain the usage of Regular Expression in JMeter. Also discuss the difference between 'contains' and 'matches'.
Pattern-based regular expressions are used to find and manipulate text in Jmeter. JMeter uses the pattern matching software Apache Jakarta ORO to parse regular expressions or patterns used throughout a JMeter test plan.

We can save a lot of time and have more flexibility when creating or improving a Test Plan by using regular expressions. When it's impossible or very difficult to predict an outcome, regular expressions provide an easy way to acquire information from sites. Regular Expressions are used to dynamically extract values from responses. These values can be kept for reporting purposes or used in a subsequent request. Both Pre-Processors and Post-Processors make use of regular expressions.

The distinction between contains and matches, as used on the Response Assertion test element, is worth mentioning.

* The term “contains” indicates that at least some of the target was matched by the regular expression. Consider the string ‘alphabet’ and the regular expression ‘ph.b.’. Because the regular expression matches the substring 'phabe', we can say that 'alphabet' contains 'ph.b.'.

* The term "matches" refers to the regular expression matching the entire target. As a result, 'alphabet' and 'al.*t' are "matched."
Advertisement