Alex Rivera | Logout

Regexp matching of list of quotes strings - unquoted

Asked 2008-09-29T05:24:35.557
10

in Javascript, the following:

var test = '"the quick" "brown fox" "jumps over" "the lazy dog"';
var result = test.match(/".*?"/g);
alert(result);

yields "the quick","brown fox","jumps over","the lazy dog"

I want each matched element to be unquoted: the quick,brown fox,jumps over,the lazy dog

what regexp will do this?

Edit
Report

1 Answer

7

This seems to work:

var test = '"the quick" "brown fox" "jumps over" "the lazy dog"';
var result = test.match(/[^"]+(?=(" ")|"$)/g);
alert(result);

Note: This doesn't match empty elements (i.e. ""). Also, it won't work in browsers that don't support JavaScript 1.5 (lookaheads are a 1.5 feature).

See http://www.javascriptkit.com/javatutors/redev2.shtml for more info.

answered 2008-09-29T05:55:10.553

Your Answer