gekomad
gekomad

Reputation: 565

Regex to extract any string (with double quote) between double quote

I can't figure out how to extract any string between double quote, the string could contains a double quote, example:

""aa"     => "aa
"aa"      => aa
""        =>
"a\nb"    => a\nb
"\u0082"  => \u0082
"ᅚ竁퇈"   => ᅚ竁퇈

I tried \"([^\"]*)\" but fails on ""aa" => "aa

Upvotes: 0

Views: 54

Answers (1)

Kubator
Kubator

Reputation: 1383

Your example ""a" can't be handled because You do not know if take null or "aa.

Anyway If Your samples are on one line, you can utilize regex begining and end:

sed 's/^"//;s/"$//'

Test:

$ cat file
""aa"
"aa"
""
"a\nb"
"\u0082"
"ᅚ竁퇈"

$ cat file | sed 's/^"//;s/"$//'
"aa
aa

a\nb
\u0082
ᅚ竁퇈

Upvotes: 1

Related Questions