There are several ways to do it with regular expressions, but in any
case, the patterns you want to extract needs to be enclosed in
parentheses (which makes them capturing groups).
One way would then be to use String#match on your input string (see Class: String (Ruby 1.9.3)), which
returns an object of type MatchData. The example in the aforementioned
URL shows how you can extract the matched strings from the MatchData
object.
txt.gsub(/\r?\n/,“”).scan(/\b(href|datetime)=“(.*?)”/).
each_slice(2) do |(k,v),(k1,v1)|
p [v.split(‘/’).last,v1.split(‘T’).first] if k==“href” &&
k1==“datetime”
end
txt.gsub(/\r?\n/,“”).scan(/\b(href|datetime)=“(.*?)”/).
each_slice(2) do |(k,v),(k1,v1)|
p [v.split(‘/’).last,v1.split(‘T’).first] if k==“href” &&
k1==“datetime”
end
I think the code is getting thrown off by this line. I deleted the
“annotated by” part and made it similar to the other lines. Then the
code returns nothing.
Actually, is there a way to just extract “J_Doe”. Forget about
the date/time for now. (I can filter this elsewhere)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.