krn
krn

Reputation: 6815

Ruby regex: extract text between quotes

What is the best way to get quoted words / phrases out of the text?

This my attempt does not work properly:

text.scan(/\"([^"]+)/)

Upvotes: 13

Views: 19924

Answers (1)

jjnguy
jjnguy

Reputation: 138982

I think you want:

text.scan(/"([^"]*)"/)

It works in Rubular.

Upvotes: 41

Related Questions