(.*)
is a greedy pattern, it tries to match as much as it can, including the commas
test1.txt, test2.txt, test3.txt
^------------------^^
all of this is |
matched by .* this is matched by ,
The last chunk is not matched, because it's not followed by a comma.
You can use non-greedy matching using .*?
Alternatively, you can to just do rawFileList.stripSuffix("\n").split(", ").toList
Also, "ls -m ~".!!
doesn't work, splitting output on commas won't work if filenames contain commas, "s"ls -m $path".!!
is asking for shell injection, and new File(path).list()
is way better in all aspects.