Reputation: 7957
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
Reputation: 26667
Something like
/\d+(?=,\d+-\d+,\d+}$)/
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