我有以下模板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?
答案 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值。