开发者

Ignoring new line characters using regex [closed]

开发者 https://www.devze.com 2023-03-31 05:58 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_StackOverflow中文版 Closed 11 years ago.

I have the below template 1000 times and need to extract the value between library and \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 

How can I do that using regular expressions and perl?


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;


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

Should capture the x.y.z value, as long as the string is always preceded by the word "library". The regex $1 value is only filled if a match is found.

0

精彩评论

暂无评论...
验证码 换一张
取 消