in reply to Re^2: Split string in groups with non white space using regex
in thread Split string in groups with non white space using regex
Note that the string '([^|]*)(\|)([^|]*)' also successfully parses '|' '||' '|||'
c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(pp); ;; my $rx_string = '([^|]*)(\|)([^|]*)' ; ;; for my $s ( 'Thanos1983+|', 'Thanos1983+| ', 'Thanos1983+| ', 'Thanos1983+|Thanos1983+', '|Thanos1983+', ' |Thanos1983+', ' |Thanos1983+', '+++|+++', '|', '||', '|||', ) { my $parsed = my @captured = $s =~ $rx_string; if ($parsed) { print qq{'$s' -> }, pp \@captured; } else { print qq{failed to parse '$s'}; } } " 'Thanos1983+|' -> ["Thanos1983+", "|", ""] 'Thanos1983+| ' -> ["Thanos1983+", "|", " "] 'Thanos1983+| ' -> ["Thanos1983+", "|", " "] 'Thanos1983+|Thanos1983+' -> ["Thanos1983+", "|", "Thanos1983+"] '|Thanos1983+' -> ["", "|", "Thanos1983+"] ' |Thanos1983+' -> [" ", "|", "Thanos1983+"] ' |Thanos1983+' -> [" ", "|", "Thanos1983+"] '+++|+++' -> ["+++", "|", "+++"] '|' -> ["", "|", ""] '||' -> ["", "|", ""] '|||' -> ["", "|", ""]
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Split string in groups with non white space using regex
by thanos1983 (Parson) on Jan 05, 2018 at 12:39 UTC | |
by AnomalousMonk (Archbishop) on Jan 05, 2018 at 14:14 UTC |