使用正则表达式忽略换行符

时间:2011-08-29 12:14:35

标签: regex perl

我有以下模板1000次,需要在库和\n\n\n\n之间提取值:

this identifier L99203 which is blah\n\nto the idnetifier of the library x.y.z\n\n\n\nYou should use this number for your solution to be right\n\n\n\no yes\n\n\n\nconnect ot db 

我怎样才能使用正则表达式和perl?

2 个答案:

答案 0 :(得分:1)

my $template = "this identifier L99203 which is blah\n\nto the idnetifier of the library x.y.z\n\n\n\nYou should use this number for your solution to be right\n\n\n\no yes\n\n\n\nconnect ot db " x 1000;
my @values = $template =~ /of the library (.*)\n\n\n\n/g;

答案 1 :(得分:0)

if ( $str =~ (?:library\s?)(.*?)(?:\\n|$) ) {
    $field = $1;
}

应捕获x.y.z值,只要该字符串始终以单词“library”开头。只有找到匹配项才会填充正则表达式$ 1值。