# Re: Grabbing quoted substrings

**URL:** <https://www.ruby-forum.com/t/re-grabbing-quoted-substrings/80006>\
**Category:** Ruby\
**Created:** [December 20, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/re-grabbing-quoted-substrings/80006 "2006-12-20T20:33:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [December 20, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/re-grabbing-quoted-substrings/80006/1 "2006-12-20T20:33:36Z")

</div>

From: mitchell

> a.scan(/"([^"]+)"/).flatten

No need to use flatten if you don’t use the (unnecessary) grouping:

a.scan( /"[^"]+"/ )  
or  
a.scan( /".+?"/ )

(Both, of course, assuming no escaped backslashes in the content. It’s  
not hard to come up with a regexp that accepts those, though at some  
point perhaps Ara’s eval solution is easier.)

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [December 20, 2006, 8:41pm UTC](https://www.ruby-forum.com/t/re-grabbing-quoted-substrings/80006/2 "2006-12-20T20:41:39Z")

</div>

Gavin K. wrote:

> > >
> 
> a.scan( /".+?"/ )
> 
> (Both, of course, assuming no escaped backslashes in the content. It’s  
> not hard to come up with a regexp that accepts those, though at some  
> point perhaps Ara’s eval solution is easier.)

Though that will capture the surrounding quotes as well, which was not  
specified in the requirements.

Tom W.
