Split line with perl

前端 未结 5 680
深忆病人
深忆病人 2021-01-23 03:57
   title: Football team: Real Madrid stadium: Santiago Bernabeu players: Zinédine Zidane, Ronaldo, Luís Figo, Roberto Carlos, Raúl personnel: José Mourinho (head coach)          


        
5条回答
  •  独厮守ぢ
    2021-01-23 04:43

    The best way is to use the split command using a zero-width lookahead:

    $string = "title: Football team: Real Madrid stadium: Santiago Bernabeu players: Zinédine Zidane, Ronaldo, Luís Figo, Roberto Carlos, Raúl personnel: José Mourinho (head coach) Aitor Karanka (assistant coach (es))";
    
    @split_string = split /(?=\b\w+:)/, $string;
    

提交回复
热议问题