-1

html is string like:

<xxx name1 = "value1" name2 = "value2">

How to use regular expression to parse key-value pairs into a hash (like {"name1": "value1", "name2": "value2"})? The tag does not matter now.

I am new to ruby and have no idea how to start. Any hints? Thanks

UPDATE

My question is how to use regex to do parsing. I know that third party is a good option. But I am just curious about how to use regex to do parsing.

BAE
  • 8,550
  • 22
  • 88
  • 171

1 Answers1

0

Regardless of the programming language, parsing html using regexp is not a good idea. In case of Ruby, Nokogiri is a good option.

Peter Pei Guo
  • 7,770
  • 18
  • 35
  • 54