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
In reply to Re^2: Split string in groups with non white space using regex
by thanos1983
in thread Split string in groups with non white space using regex
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |