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

    Hello AnomalousMonk,

    Thanks for the test script I had no idea that the regex can match so many combinations.

    BR / Thanos

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

      When you have a convenient exercise framework, it's sometimes hard to stop thinking up and testing new regexes and strings. In fact, my experience has been that you might just as well go ahead and write a formal Test::More (or similar) test framework immediately, because that's what you'll be doing in the end.


      Give a man a fish:  <%-{-{-{-<