in reply to Re: Split string in groups with non white space using regex
in thread Split string in groups with non white space using regex

Hello karlgoethebier,

To be honest I was just about to post another possible solution:

#!/usr/bin/perl use strict; use warnings; use feature 'say'; my @tests = ('Thanos1983+|Thanos1983+', 'Thanos1983+| ', 'Thanos1983+|'); for (@tests) { say "I found:\t\$1: '$1'\t\$2: '$2'\t\$3: '$3'" if /(.*)(\|)(.*)/; } __END__ $ perl test.pl I found: $1: 'Thanos1983+' $2: '|' $3: 'Thanos1983+' I found: $1: 'Thanos1983+' $2: '|' $3: ' ' I found: $1: 'Thanos1983+' $2: '|' $3: ''

Thanks for the tip of using m/(.+)(\|)(.+)/ this is also works for the first two cases but not for the third.

Sample of code:

#!/usr/bin/perl use strict; use warnings; use feature 'say'; my @tests = ('Thanos1983+|Thanos1983+', 'Thanos1983+| ', 'Thanos1983+|'); for (@tests) { say "I found:\t\$1: '$1'\t\$2: '$2'\t\$3: '$3'" if /(.+)(\|)(.+)/; } __END__ $ perl test.pl I found: $1: 'Thanos1983+' $2: '|' $3: 'Thanos1983+' I found: $1: 'Thanos1983+' $2: '|' $3: ' '

Thank you for your time and effort.

BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^3: Split string in groups with non white space using regex
by karlgoethebier (Abbot) on Jan 04, 2018 at 12:41 UTC

    (.+)\|? AKA one or none?

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help