ruby on rails - regular expression a string -


i need regular expression convert following object:

"{:email=>[\"has been taken\"], :name=>[\"has been taken\"]}" 

to

email has been taken, name has been taken 

▶ str = "{:email=>[\"has been taken\"], :name=>[\"has been taken\"]}" ▶ eval(str).map { |k, v| [k.capitalize, v].join(' ') }.join(', ') #⇒ "email has been taken, name has been taken" 

with scan:

▶ str.scan(/:(\w+)=>\["(.*?)"\]/).map |k, v| ▷   [k.capitalize, v].join(' ') ▷ end.join(', ') #⇒ "email has been taken, name has been taken" 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -