in reply to Re: Parse string for fields
in thread Parse string for fields
That will work though it leaves a trailing space.my $string = "name+C.+city+loc.+loc2+++++++++++++++++++++++++B+++v+G++ ++"; $string =~ s/\+(?!\+)|\+{3,}.*$/ /g; print $string, "\n";
Now @fields[0..4] contain what you want, and the garbage ("BvG") is in $fields[5].my @fields = split /\+/, $string, 6;
Take it one step further like this:
my $parsed = join " ",(split /\+/, $string, 6)[0..4];
Do it the hard way with a substitution regexp, or the easy way with split. :)
Dave
|
|---|