I’m trying to create two a regex to add quotes to some values in a string. Basically the string would be like this:
999 date Doe, John E. London 123456789
And I want to surround the name so that if this file is exported to a csv, it won’t be separated. This is what I have so far
$line =~ s/([^\s{2,}]*,[^\s{2,}]*)/"$1"/g;
I think it should find any comma and anything near it until it finds two or more spaces but it’s not working. Thanks for the help.
You asked for anything except 2 or more spaces.
I agree that
unpackis the more natural way to do this. Butsplitis a way to use a cookie-cutter in the shape of a pattern. Anything not in that pattern is a return field. So this:might be enough.