In some languages, strings are started and ended with a quote mark ('
). And quote itself is escaped by writing it twice sequentially. For example, empty string is written as ''
, and I'm
is written as 'I''m'
.
This question is about find out all non-overlapping strings from left to right in such format from the given input, while ignoring anything between or around these string literals.
Input / Output
You are given a string contains only printable ASCII. Quotes ('
) in inputs are always paired. And you need to find out all non-overlapping quoted strings in it. Output these strings in the order they appeared.
You are free to choose any acceptable I/O format you want. However, formats of strings for input and output MUST be the same. Which means that you cannot take raw string as input, and claim that your output string are formatted in quotes, with quotes escaped by writing twice. As this may trivialize the challenge.
Test Cases
All testcases here are written in JSON format.
Input -> Output # Comment (not a part of I/O)
"abc" -> [] # text out side quotes are ignored
"''" -> [""] # '' is an empty string
"''''" -> ["'"] # two sequential quotes in string converted into a single one
"'abc'" -> ["abc"]
"a'b'" -> ["b"]
"'b'c" -> ["b"]
"a'b'c" -> ["b"]
"abc''def" -> [""]
"'' ''" -> ["", ""] # there are 2 strings in this testcase
"'abc' 'def'" -> ["abc", "def"]
"'abc'def'ghi'" -> ["abc", "ghi"] # separator between strings could be anything
"'abc''def'" -> ["abc'def"]
"a'bc''de'f" -> ["bc'de"]
"''''''" -> ["''"]
"'''a'''" -> ["'a'"]
"''''a''" -> ["'", ""]
"''''''''" -> ["'''"]
"'abc\"\"def'" -> ["abc\"\"def"] # double quotes do not have special meanings
"'\\'\\''" -> ["\\", ""] # backslashes do not have special meanings
"'a'#48'b'" -> ["a", "b"] # hash signs do not have special meanings
"a,'a','a,''a''','a,''a'',''a,''''a'''''''" -> ["a", "a,'a'", "a,'a','a,''a'''"] # Testcase suggested by Command Master
And here are above testcases formatted with line breaks.
Rules
- This is code-golf, so shortest code wins.
a,'a','a,''a''','a,''a'',''a,''''a'''''''
\$\endgroup\$