Parse unpleasant string in ruby to derive a condition -


i have response string gets returned webservice isn't json exactly, nor other kind of hashable object, can serialize. i'm new regex i'm trying learn how can extract needed pieces ruby code.

the string horrendous, i'm not sure how go comparing two. don't know regex that's hindrance. thank in advance can provide.

the parameter passed partialresult method should valid json. can use regex, extract string.

require 'json' hsh = json.parse str.scan(/partialresult\((.*)\)/)[0][0] #=> {"q"=>"laptop bag", "r"=>[["laptop bag", [["electronics", 3944]]], "laptop bags 15.6 inch laptops", "laptop bags women", "laptop bag 15.6", "laptop bags 17.3 in laptops", "rolling laptop bag", "laptop bag wheels", "laptop bag 17\""]}  

to check common string

hsh["r"].flatten && hsh["q"].flatten #=> "laptop bag"  

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -