| Author |
regular expression help
|
rick simpson
Greenhorn
Joined: Oct 15, 2008
Posts: 8
|
|
Hi,
I've been pounding my brain on this one and can't quite get the expression right to pull out what I want. Below is the feed I'm trying to parse. I'm tying to find the id number for any product where "has_eula" is true.
I've tried:
--this does the trick to distinguish each product uniquely, but it captures all products, true and false for eula
If I do something like:
-- It stops on a true, but it gets everything between the first "id" and the first true, (true and false ids mixed together as a single capture).
I can't figure out how to just capture the products with eula set to true in 1 expression. (I need to do it in one expression cause I'll be using it in a JMeter response assertion).
Any times appreciated.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
do you REALLY have to do it in one step?
I would personally go through the list of records and pick out the lines where "has_eula" is true, and THEN go through those lines to find their ID number.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
If this is always the format of data you are processing, why not try something like this:
-> if the record (one line of text, or whatever) contains "has_eula":false skip it
-> otherwise, process the line to get the ID (or whatever).
If you really need to do it with reg.exp. than something like this "product_id":[\d]* should get you the part where product_id is. On the other hand, this shouldn't take long to process with StringTokenizer.
|
The quieter you are, the more you are able to hear.
|
 |
rick simpson
Greenhorn
Joined: Oct 15, 2008
Posts: 8
|
|
|
I need to do it in one step because i'm using the expression in a JMeter response assertion. I'm basically parse through a http response for data. I only get one shot at.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
rick simpson wrote:
--this does the trick to distinguish each product uniquely, but it captures all products, true and false for eula
If I do something like:
-- It stops on a true, but it gets everything between the first "id" and the first true, (true and false ids mixed together as a single capture).
That is because that is how you defined it. Notice that the pattern between the id component and the eula component is "(,.*?)", which matches everything after the comma including the boundaries separating the different "id" lines.
rick simpson wrote:
I can't figure out how to just capture the products with eula set to true in 1 expression. (I need to do it in one expression cause I'll be using it in a JMeter response assertion).
You need to prevent matches that cross id lines. For example, the lines are enclosed between the curly braces -- so it is not possible to have curly braces between the id component and the eula component. A possible option is to use "(,[^{]*?)", instead of "(,.*?)".
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: regular expression help
|
|
|