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 に答える