Đorđe Zeljić
Đorđe Zeljić

Reputation: 1825

How to parse quoted string with quotes in it

How to get sql query (second parameter of FORM func)

=FORM("onname", "SELECT "lname", "fname", "year" from table")

I tried with:

.match(/^=FORM\("(.*)", *"((?:.|\n)*)"\)$/i)

but it doesn't work.

Upvotes: 2

Views: 133

Answers (3)

mmdemirbas
mmdemirbas

Reputation: 9158

See it in action:

^=FORM\(".*?",\s*"(.*)"\)$

Grab 1st capturing group to use.

Upvotes: 0

sp00m
sp00m

Reputation: 48817

Here is a very specific to your problem solution:

.replace(/=FORM\("[^"]+", "(.*)"\)/ig, "$1")

See the demo

Upvotes: 0

João Silva
João Silva

Reputation: 91299

var s = '=FORM("onname", "SELECT "lname", "fname", "year" from table")';
var sql = s.match(/^=FORM\("[^"]+", "(.+)"\)$/i)[1];

Upvotes: 3

Related Questions