in reply to Re: Parse string for fields
in thread Parse string for fields

my $string = "name+C.+city+loc.+loc2+++++++++++++++++++++++++B+++v+G++ ++"; $string =~ s/\+(?!\+)|\+{3,}.*$/ /g; print $string, "\n";
That will work though it leaves a trailing space.
Why not use split?

my @fields = split /\+/, $string, 6;
Now @fields[0..4] contain what you want, and the garbage ("BvG") is in $fields[5].

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


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein