babp has asked for the wisdom of the Perl Monks concerning the following question:

Hi I want to match following string:

string ====== ERROR: below not seen in Profile: | hwp | path | description | -+-----------+-------------+-------------+- | 1/0/0/0/0 | /dev/tty | TEST | my first match will be: ERROR: below not seen in Profile: 2nd match will be | hwp | path | description | 3rd match will be | 1/0/0/0/0 | /dev/tty | TEST |
  • Comment on matching a multi line string with separated by diffrent delimeters
  • Download Code

Replies are listed 'Best First'.
Re: matching a multi line string with separated by diffrent delimeters
by kennethk (Abbot) on Apr 24, 2012 at 14:30 UTC

    What have you tried? What didn't work? See How do I post a question effectively?. The challenge here is not what you want to match but what you don't. Given just the sample code, you could get your requested result with: /^(ERROR.+?)^.+^(.+?)^.+^(.+?$)/ms;, but I sincerely doubt that's actually helpful. A readthrough of perlretut might be helpful.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: matching a multi line string with separated by diffrent delimeters
by Anonymous Monk on Apr 24, 2012 at 14:26 UTC
Re: matching a multi line string with separated by diffrent delimeters
by Kenosis (Priest) on Apr 24, 2012 at 15:26 UTC

    Although kennethk's solution works perfectly well to generate the match results you've listed, here's another option:

    my($first, $second, $third) = (split /\n/, $string)[0,2,4];

    Hope this helps!