I have the following data in a CSV file.
2454,"dum my"
12345,"dummy"
300001,"du m m y"
I was wondering, what regular expression I can use, to turn them into
002454,"dummy"
012345,"dummy"
300001,"dummy"
Thanks.
I have the following data in a CSV file.
2454,"dum my"
12345,"dummy"
300001,"du m m y"
I was wondering, what regular expression I can use, to turn them into
002454,"dummy"
012345,"dummy"
300001,"dummy"
Thanks.
I'd recommend reading and rewriting the CSV file with Text::CSV_XS and manipulating the fields individually, but if you must just use a regex, something like:
sub strip_spaces { my $str = shift; $str =~ y/ //d; $str }
s/(\d+)/ sprintf '%.6d', $1 /e;
s/("[^"]+"$)/ strip_spaces($1) /e;