• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regular expression help

 
rick simpson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rick simpson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21489
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic