Inspired by this StackOverflow question.
We'll take three inputs:
- A delimiter-character
Dto split on
- A character
Ibetween two of which we ignore the delimiter character (I know, that sounds vague, but I'll explain it below)
- A string
A list/array containing the substrings after the split.
Input: D = ',' I = '"' S = '11020199,"Abc ",aduz,,444,bieb,dc,2 ,2222.00,whatever 5dc,222.22,22.00,"98,00","12,000,000",21-09-2018, 06:00,",-,"' Output: ['11020199', 'Abc ', 'aduz', '', '444', 'bieb', 'dc', '2 ', '2222.00', 'whatever 5dc', '222.22', '22.00', '98,00', '12,000,000', '21-09-2018', ' 06:00', ',-,']
Why? Splitting on comma would normally also split
,-, in two/three pieces. But because they are within the
I input character, we ignore ignore the split here.
- You can assume there will always be an even amount of
Icharacters in the input-string.
- You can assume the character
Iwill always have a
Dnext to it (except when it's the first or last character of the input) which can still be properly split. So you won't have something like
D = ','; I = '"'; S = 'a,b"c,d"e,f', nor anything like this
D=','; I='"'; S='a",b,"c'.
- The input-string
Scould contain none of either
I. If it contains no
D, we output a list with the entire input-string as only item.
- The output list won't contain the character
Ianymore, even when it contained no
D(as you can see at the
'Abc 'in the example above).
- It is possible that the substring within
D. For example:
D = ','; I = '"'; S = 'a,",",b,"c","d,e,,",f'would result in
['a', ',', 'b', 'c', 'd,e,,', 'f'].
- You can assume that
Dwill never be at the start or end of
S, so you won't have to deal with trailing / leading empty items.
- When an input has two adjacent
D, we'll have an empty item. I.e.
D = ','; I = '"'; S = 'a,"b,c",d,,e,"",f'would result in
['a', 'b,c', 'd', '', 'e', '', 'f'].
- You can assume the inputs and outputs will only contain printable ASCII in the range
[32, 126](so excluding tabs and newlines).
- You are also allowed to output all items new-line delimited instead of returning/outputting a list/array (especially for those languages that don't have lists/arrays; i.e. Retina).
- You are allowed to output the list in reversed order if it saves bytes. You are not allowed to output it in sorted or 'shuffled' order, though. So
D = ','; I = 'n'; S = 'a,2,b,3,c'can be output as
[c,3,b,2,a], but not as
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Input: D = ','; I = '"'; S = 'a,"b,c",d,,e,"",f' Output: ['a', 'b,c', 'd', '', 'e', '', 'f'] Input: D = ','; I = '"'; S = '11020199,"Abc ",aduz,,444,bieb,dc,2 ,2222.00,whatever 5dc,222.22,22.00,"98,00","12,000,000",21-09-2018, 06:00,",-,"' Output: ['11020199', 'Abc ', 'aduz', '', '444', 'bieb', 'dc', '2 ', '2222.00', 'whatever 5dc', '222.22', '22.00', '98,00', '12,000,000', '21-09-2018', ' 06:00', ',-,'] Input: D = ' '; I = ','; S = 'this is a test , to see if you understand it, or not , hmmm, I think I have too many commas , or not , perhaps..' Output: ['this', 'is', 'a', 'test', ' to see if you understand it', 'or', 'not', ' hmmm', 'I', 'think', 'I', 'have', 'too', 'many', 'commas', ' or not ', 'perhaps..'] Input: D = 'x'; I = 'y'; S = 'contains no lowercase X nor Y' Output: ['contains no lowercase X nor Y'] Input: D = '1'; I = '3'; S = '3589841973169139975105820974944592078316406286208948254211370679314' Output: ['58984197', '69', '9975105820974944592078', '64062862089482542', '', '70679', '4'] Input: D = ' '; I = 'S'; S = 'regular split on spaces' Output: ['regular', 'split', 'on', 'spaces']