Perl是一种功能强大的编程语言,它内置了对正则表达式的支持
my $file = "example.txt";
open(my $fh, '<', $file) or die "Could not open file '$file' $!";
my $content = do { local $/; <$fh> };
close($fh);
my @emails = $content =~ /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g;
$content =~ s/apple/orange/g;
my @values = split(/,/, $content);
my ($host, $path) = $content =~ /(?:([a-zA-Z0-9.-]+)(?::[0-9]+)?)(\/.*)/;
my @emails = $content =~ /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/gi;
通过结合这些技巧,你可以在Perl中有效地使用正则表达式来查找、替换、分割和处理文件内容。