I have the following regular expression in Ruby:
\<name\>(.+)\<\/name\>
Within in if statement, like so:
if line =~ /\<name\>(.+)\<\/name\>/
Is there any way to get the value of the group (.+)
?
Thanks in advance!
I have the following regular expression in Ruby:
\<name\>(.+)\<\/name\>
Within in if statement, like so:
if line =~ /\<name\>(.+)\<\/name\>/
Is there any way to get the value of the group (.+)
?
Thanks in advance!
Rather than use regex to parse XML or HTML, use a real parser. I like Nokogiri:
require 'nokogiri'
doc = Nokogiri::XML('<somecontainingtags><name>blah</name></somecontainingtags>')
# find all occurences
doc.search('//name').map {|n| n.inner_text } # => ["blah"]
# find the first occurance
doc.at('//name').inner_text # => "blah"