svn commit: r890851 - /jakarta/jmeter/trunk/xdocs/usermanual/regular_expressions.xml

[email protected]
Newsgroups gmane.comp.jakarta.jmeter.devel
Message-ID <[email protected]>
Author: sebb
Date: Tue Dec 15 15:59:12 2009
New Revision: 890851

URL: http://svn.apache.org/viewvc?rev=890851&view=rev
Log:
Improve RE docs

Modified:
    jakarta/jmeter/trunk/xdocs/usermanual/regular_expressions.xml

Modified: jakarta/jmeter/trunk/xdocs/usermanual/regular_expressions.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/regular_expressions.xml?rev=890851&r1=890850&r2=890851&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/regular_expressions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/regular_expressions.xml Tue Dec 15 15:59:12 2009
@@ -74,36 +74,51 @@
 </p>
 </subsection>
 <subsection name="&sect-num;.2 Examples" anchor="examples">
+<h3>Extract single string</h3>
 <p>
-Extract single string
-<br/>
 Suppose you want to match the following portion of a web-page: 
 <br/>
-name="file" value="readme.txt" and you want to extract readme.txt.
+<code>name="file" value="readme.txt"></code>
 <br/>
-A suitable reqular expression would be:
+and you want to extract <code>readme.txt</code>.
+<br/>
+A suitable regular expression would be:
 <br/>
-name="file" value="(.+?)"
+<code>name="file" value="(.+?)"></code>
 <p>
 The special characters above are:
 </p>
 <ul>
 <li>( and ) - these enclose the portion of the match string to be returned</li>
-<li>. - match any character. + - one or more times. 
-? - don't be greedy, i.e. stop when first match succeeds</li>
+<li>. - match any character</li>
+<li>+ - one or more times</li> 
+<li>? - don't be greedy, i.e. stop when first match succeeds</li>
 </ul>
 <p>
-Note: without the ?, the .+ would continue past the first " until it found the last possible " - probably not what was intended.
+Note: without the ?, the .+ would continue past the first <code>"></code>
+until it found the last possible <code>"></code> - which is probably not what was intended.
 </p>
-<p>Extract multiple strings</p>
-
-Suppose you want to match the following portion of a web-page: name="file.name" value="readme.txt" and you want to extract file.name and readme.txt.
+<p>
+Note: although the above expression works, it's more efficient to use the following expression:
+<br/>
+<code>name="file" value="([^"]+)"></code>
+where<br></br>
+[^"] - means match anything except "<br></br>
+In this case, the matching engine can stop looking as soon as it sees the first <code>"</code>, 
+whereas in the previous case the engine has to check that it has found <code>"></code> rather than say <code>" ></code>.
+</p>
+<h3>Extract multiple strings</h3>
+<p>
+Suppose you want to match the following portion of a web-page:<br/>
+<code>name="file.name" value="readme.txt"</code> 
+and you want to extract both <code>file.name</code> and <code>readme.txt</code>.
 <br/>
 A suitable reqular expression would be:
 <br/>
-name="(.+?)" value="(.+?)"
+<code>name="([^"]+)" value="([^"]+)"</code>
 <br/>
 This would create 2 groups, which could be used in the JMeter Regular Expression Extractor template as $1$ and $2$.
+</p>
 <p>
 The JMeter Regex Extractor saves the values of the groups in additional variables.
 </p>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.