Search code examples
regexperlsplitnon-greedy

Perl split regex non greedy fit with ">" as a separator


i'd like to split string with two or more ">", split function should brake string in first ">" and others put to second sting in list.

i try

$text = "tobash> hubba -> http://nonexists100101.net";

@op = split(/>{1}/, $text);

but split still breaks in every ">"


Solution

  • This is not how {1} works (in fact, {1} never does anything at all). According to perldoc split has a third limit parameter. Try:

    split(/>/, $text, 2)
    

    That will return at most 2 substrings.