如何只在perl中的符号之间选择句子

时间:2015-02-25 11:06:58

标签: regex perl

我需要在数组之间插入符号,如下所示。

my $string = "<hi how r u><<<what is your name>>><what is your age><<<hi how r u>>><this is idiot><<<iam fine>>>";

我需要grep as

@str = ("what is yourname","hi how r u","iam fine");
@str1 = ("hi how r u","what is your age","this is idiot")

1 个答案:

答案 0 :(得分:1)

(?<=<<<)([\w ]+)(?=>>>)|([\w ]+)

试试这个。第一组将是你的第一组,第二组是第二组。参见演示。

https://regex101.com/r/wU7sQ0/8