I have a string that content a link of a youtube page .
Like:
i want get the value of v:
PupR5V9aE2s
How i can do?
Thanks
I have a string that content a link of a youtube page .
Like:
i want get the value of v:
PupR5V9aE2s
How i can do?
Thanks
Alle Sunday 24 February 2008, Luca R. ha scritto:
I have a string that content a link of a youtube page .
Like:
The Great Trafalgar Square Freeze - YouTubei want get the value of v:
PupR5V9aE2sHow i can do?
Thanks
If you know that the part of the string you want is delimited by v= and
&, you
can use this:
str.match(/v=([^&]*)/)[1]
Stefano
Thanks stefano for the responce
There are 2 possible links:
str.match(/v=([^&]*)/)[1]
Is your command valid also for the second link?
Thanks
Stefano C. wrote:
Alle Sunday 24 February 2008, Luca R. ha scritto:
I have a string that content a link of a youtube page .
Like:
The Great Trafalgar Square Freeze - YouTubei want get the value of v:
PupR5V9aE2sHow i can do?
ThanksIf you know that the part of the string you want is delimited by v= and
&, you
can use this:str.match(/v=([^&]*)/)[1]
Stefano
On 24/02/2008, Luca R. [email protected] wrote:
I have a string that content a link of a youtube page .
Like:
The Great Trafalgar Square Freeze - YouTube
irb(main):001:0> require ‘uri’
=> true
irb(main):002:0> res = URI.split(’
The Great Trafalgar Square Freeze - YouTube’)
=> [“http”, nil, “it.youtube.com”, nil, nil, “/watch”, nil,
“v=PupR5V9aE2s&test=1”, nil]
gives you an array of:
-Thomas
Alle Sunday 24 February 2008, Luca R. ha scritto:
Thanks
If you know that the part of the string you want is delimited by v= and
&, you
can use this:str.match(/v=([^&]*)/)[1]
Stefano
Yes. The regexp I used looks for the string v= followed by any number of
characters which are not ‘&’. Those characters are put into the first
group of
the returned MatchData. Since your second link doesn’t contain the ‘&’,
the
match will go on until the end, which should give you what you want.
Stefano
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs