• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

regular expression help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13073
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
catch it before it slithers away! Oh wait, it's a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic