Question: This program output should be an string but it is array

```
hi = "<ui><li>Welcome to select</li><li>hi</li><li>bye</li></ul>"

i = hi.scan(/<ui>(.*?)<\/ul/)
puts i

```

Output

```
[["<li>Welcome to select</li><li>hi</li><li>bye</li>"]]

```

but i want output like this 

```
 <li>Welcome to select</li><li>hi</li><li>bye</li>

```

Then i want all the <\li>(.\*?)</li> tags in seperate line 

Like this 

```
 Welcome to select
 hi
 bye

```

Answer: 
You should use [Nokogiri](http://www.nokogiri.org) to parse HTML:

```
require 'nokogiri'

hi = '<ul><li>Welcome to select</li><li>hi</li><li>bye</li></ul>'

Nokogiri::HTML.fragment(hi).css('ul li').each do |li|
  puts li.text
end

```

Output:

```
Welcome to select
hi
bye

```
If you want the output in separate lines, then you could use ruby array's [flatten](http://www.ruby-doc.org/core-2.2.0/Array.html#method-i-flatten) method and then loop through it to print them in separate lines.
Flatten converts the array of arrays to a single dimensional array.

```
hi.scan(/<li>(.*?)<\/li>/).flatten.each {|x| puts x}

```

Output:

```
Welcome to select
hi
bye

```