From: "Иван Бишевац" Date: 2012-10-15T04:18:59+09:00 Subject: Re: best way to extract data from a string? --047d7b10cf37ef37a004cc09ca21 Content-Type: text/plain; charset=UTF-8 2012/10/14 Erez Ben shoham > Hi > I have a string > str = "file name_Width34.56_Height45.97_.jpg" > > what is the best way to extract the the data from the string? > > file name => "file name.jpg" > width => "34.56" > hieght => "45.97" > > -- > Posted via http://www.ruby-forum.com/. > > string = "file name_Width34.56_Height45.97_.jpg" string =~ /(.+)_Width(\d+.\d+)_Height(\d+.\d+)_.jpg/ puts $1, $2, $3 http://rubular.com is your friend, try it. --047d7b10cf37ef37a004cc09ca21 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
2012/10/14 Erez Ben shoham <lists@ruby-forum.com>
Hi
I have a string
str =3D "file name_Width34.56_Height45.97_.jpg"

what is the best way to extract the the data from the string?

file name =3D> "file name.jpg"
width =3D> "34.56"
hieght =3D> "45.97"

--
Posted via http://= www.ruby-forum.com/.

string =3D "file name_Width34.56= _Height45.97_.jpg"
string =3D~ /(.+)_Width(\d+.\d+)_Height(\= d+.\d+)_.jpg/
puts $1, $2, $3

http://rubular.com is your friend, try it.
--047d7b10cf37ef37a004cc09ca21--