Turn: detailed jmeter regular Expressions (1)

Source: Internet
Author: User

1. Overview

JMeter contains the template matching software Apache Jakarta ORO. There are some documents about it on the Jakarta website, such as a summary of the pattern matching characters:

Http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html.

In addition, there may be some help with the old version of the software documentation Oromatcher User s Guide. URL address: http://www.savarese.org/oro/docs/OROMatcher/index.html.

The template match for JMeter is similar to the model of the Perl language. A complete Perl installation contains many documents about regular expressions (search Perlrequick, Perlretut, Perlre, Perlreref).

It is necessary to clarify the differences between inclusions (Contains) and Match (Matches), which are used in response to the assertion test element:

Inclusion (Contains) means that the regular expression matches at least partially the target, for example, ' alphabet ' contains ' ph.b. ' Because the regular expression matches its substring ' phabe '.

Match (Matches) means that the regular expression matches the target exactly. For example, ' Alphabet ' matches ' al.*t '.

In this case, it is equivalent to using the ^ and $ encapsulation regular expressions, i.e. ' ^al.*t$ '. But it's not always the case. For example, the regular expression ' alp|. Lp.* ' is contained in ' Alphabet ', but does not match ' alphabet '.

The reason is that when the template match finds the sequence ' ALP ' in ' alphabet ', it stops trying other combinations, and ' ALP ' differs from ' alphabet ', which does not contain ' habet '.

Unlike Perl, there is no need to encapsulate regular expressions in//.

2. Instance

1) extracting a single string

Suppose testers expect to match the following parts of a Web page: name= "file" value= "Readme.txt" > and extract Readme.txt.

A regular expression that meets the requirements:

    1. Name= "File" value= "(. +?)" >.

Some of the special characters used above include the following.

(and): encapsulates the matching string to return.

.: matches any character.

+: one or more times.

?: Don't be too greedy, stop after you find the first match.

If not, after finding the first ">, will continue to look until the last one", this is probably not what the testers expected.

Although the above expression can be achieved, it is more efficient to use the following expression: name= "file" value= "([^"]+) ", where [^"]-means matching anything (except "). In this case, the matching engine will stop searching after it finds the first right. The matching engine in the example above will look for ">.

2) Extracting multiple strings

Suppose the tester expects to match the following parts of the Web page: name= "file" value= "Readme.txt", and extracts File.name and Readme.txt.

A regular expression that meets the requirements:

    1. Name="([^"]+) " value=" ([^ "]+)"

This creates two combinations and can be used for jmeter regular expression templates, such as $1$ and $2$.

The JMeter Regular expression extractor places the combined value in the specified variable, as shown in 11-2.

(Click to view larger image) Figure 11-2 jmeter Regular Expression Extractor

Turn: detailed jmeter regular Expressions (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.