Reputation: 898
a='fdkfjsdflksdj lfkjdflksdjf["fdkljfdfl"]fkjdfldjkf["fdfdf"]dfdfsdfsdfsdfddfdfkdfj["fdfds"]fdfasdfds'
I need to fetch the values which is inside ""
that means out put should be
fdkljfdfl
fdfdf
fdfds
I have written the below coding
puts a[/\["(.*)"\]/m]
but it returns
["fdkljfdfl"]fkjdfldjkf["fdfdf"]dfdfsdfsdfsdfddfdfkdfj["fdfds"]
Can you help me to take that particular string within ""
Upvotes: 0
Views: 55
Reputation: 10251
Try:
a.scan(/"([^"]*)"/).flatten
#=> ["fdkljfdfl", "fdfdf", "fdfds"]
it will return the array of string
Upvotes: 1
Reputation: 67968
puts a.scan(/\["(.*?)"\]/m)
^^
Make your regex non greedy.Or use negation based regex.
puts a.scan(/\["([^"]*)"\]/m)
Upvotes: 2