0

I would like to use Perl's split functionality to do the following:

example string:

=foo>bar=\foo2>bar2=foo3> ...

Now I tried this:

@Array = split /=.*>/, $string

I'm expecting to get my array filled with "bar", "bar2", ...

Any idea what I'm doing wrong?

simbabque
  • 53,749
  • 8
  • 73
  • 136
  • Your regex is so greedy it takes the whole string as the delimiter and you end up with nothing. But I don't understand how the splitting should work. What happens to `foo`? And is the `\` a `\f`, or a literal backslash? – simbabque Mar 28 '17 at 09:55
  • 1
    how about this? split('=[^>]*>', $str). the first and last in the result will be empty. – Shiping Mar 28 '17 at 09:56
  • Eyyyyy, sweet. Thanks alot! Works wonders, I'll just get rid of the empty array entries and that should be fine :) – Fabio Mazzurco Mar 28 '17 at 10:00
  • `My regex is matching too much. How do I make it stop? 4 answers` This answer doesn't matched with the OP asked. – ssr1012 Mar 28 '17 at 12:46

0 Answers0