1

I've a string $string which has got list of lines, some ending with *.c, *.pdf,etc and few without any extensions(these are directories). I need to remove all lines except *.c lines. How can i do that using regular expression? I've written to get removed *.c files as below but how to do a not of it?

next if $line =~ /(\.c)/i;

Any ideas.

thanks, Sharath

4

1 回答 1

2

使用unless而不是if反转条件的意义。

next unless $line =~ /\.c$/i;

或简单地反转测试:

next if $line !~ /\.c$/i;

此外,您不需要正则表达式周围的括号,您需要$将其锚定到行尾。

于 2013-05-16T09:07:32.167 回答