divz
divz

Reputation: 7957

get particular value from a data using ruby

attributes = query(View").first["description"]

puts attribute prints following value

 "description" => "android.widget.ImageView{b10b2c28 V.ED..C. .....
I. 880,0-1760,672}

from this I have to get the value 880

the same thing from the below value i have to print the value 1760.

"description" => "android.widget.ImageView{b17b03c8 V.ED..C. ......
I. 1760,96-2832,576}

How it is possible in ruby

Upvotes: 1

Views: 43

Answers (1)

nu11p01n73R
nu11p01n73R

Reputation: 26667

Something like

/\d+(?=,\d+-\d+,\d+}$)/

Regex Demo

TEST

> print '"description" => "android.widget.ImageView{b10b2c28 V.ED..C. .....
  I. 880,0-1760,672}'.scan(/\d+(?=,\d+-\d+,\d+}$)/)[0]
=> "880"

> print '"description" => "android.widget.ImageView{b17b03c8 V.ED..C. ......
  I. 1760,96-2832,576}'.scan(/\d+(?=,\d+-\d+,\d+}$)/)[0]
=> "1760"

Upvotes: 2

Related Questions