Return-Path: Delivered-To: apmail-jakarta-jmeter-user-archive@www.apache.org Received: (qmail 34857 invoked from network); 1 Aug 2006 20:22:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Aug 2006 20:22:57 -0000 Received: (qmail 50882 invoked by uid 500); 1 Aug 2006 20:22:55 -0000 Delivered-To: apmail-jakarta-jmeter-user-archive@jakarta.apache.org Received: (qmail 50854 invoked by uid 500); 1 Aug 2006 20:22:55 -0000 Mailing-List: contact jmeter-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "JMeter Users List" Reply-To: "JMeter Users List" Delivered-To: mailing list jmeter-user@jakarta.apache.org Received: (qmail 50843 invoked by uid 99); 1 Aug 2006 20:22:55 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Aug 2006 13:22:55 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of lists@nabble.com designates 72.21.53.35 as permitted sender) Received: from [72.21.53.35] (HELO talk.nabble.com) (72.21.53.35) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Aug 2006 13:22:54 -0700 Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1G80l8-0006vE-FI for jmeter-user@jakarta.apache.org; Tue, 01 Aug 2006 13:22:34 -0700 Message-ID: <5602388.post@talk.nabble.com> Date: Tue, 1 Aug 2006 13:22:34 -0700 (PDT) From: Yanroy To: jmeter-user@jakarta.apache.org Subject: Re: using regex with beanshell In-Reply-To: <5601684.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-Sender: rmeador@wpi.edu X-Nabble-From: Yanroy References: <5583703.post@talk.nabble.com> <5601684.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Actually, yes, just moments ago I finally came up with a solution. The code isn't very pretty (I suspect beanshell never is), but it does what I need it to do. Hopefully it'll help you too. I use the java regex library to parse the result of a jmeter sampler. This code is what I typed into a beanshell assertion element in jmeter: import java.util.regex.*; String pStr = ".*?Assistment: \\((\\d+?)\\).*"; print("Regex Pattern: " + pStr); Pattern idPattern = Pattern.compile(pStr, Pattern.UNIX_LINES | Pattern.DOTALL); Matcher idMatcher = idPattern.matcher(SampleResult.getResponseDataAsString()); boolean matched = idMatcher.matches(); if (matched) { print("Matched ID: " + idMatcher.group(1)); } else { print("didn't match id"); Failure = true; FailureMessage = "Couldn't extract ID from question"; } [end code] This matches the string "Assistment: (2100)" and extracts 2100 from it (or any other number). That string is embedded in the HTML of a page. I specify the UNIX_LINES flag to the regex because I'm using linux... idk if it's really necessary. Also, you'll note the plethora of backslashes... this is because the java/beanshell compiler escapes the backslash characters once, then the regex engine does it again. Of course, this code doesn't do anything useful other than fail the assertion if it couldn't find the number. Have fun with it. Ryan -- View this message in context: http://www.nabble.com/using-regex-with-beanshell-tf2029950.html#a5602388 Sent from the JMeter - User forum at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: jmeter-user-help@jakarta.apache.org