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 tybalt89,

Works perfectly, thanks 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 AnomalousMonk (Archbishop) on Jan 04, 2018 at 18:12 UTC

    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:  <%-{-{-{-<

      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:  <%-{-{-{-<