-4

我不是最擅长正则表达式的人,所以将它们从一种语言翻译成另一种语言可能是一项艰巨的任务。

tre = re.compile("///--STRING TEXT ONE. Ends with the word EDIT.(?:.*)--///(?:(?:.*\n))*///--END is the first word in STRING TEXT TWO--///")
result = tre.sub(motionBlur_text, configContents)

如果你们能帮我把它移到 perl(我听说它更适合 reg 表达式),那将非常酷。

4

2 回答 2

2

Perl 中的正则表达式是相同的:

my $re = qr#///--STRING TEXT ONE. Ends with the word EDIT.(?:.*)--///(?:(?:.*\n))*///--END is the first word in STRING TEXT TWO--///#;
于 2013-02-19T15:45:23.487 回答
0

编译是通过qr//操作员完成的。您可以使用(大多数情况下)字符而不是“/”。我将使用大括号,因为这是 Perl 最佳实践推荐的:

my $tre = qr{///--STRING TEXT ONE. Ends with the word EDIT.(?:.*)--///(?:(?:.*\n))*///--END is the first word in STRING TEXT TWO--///};

要就地执行替换(请参阅Regexp Quote-Like Operators):

$motionBlur_text =~ s/$tre/$configContents/g;

对字符串的副本执行替换并返回它(Perl 5.14+)

my $result = $motionBlur_text =~ s/$tre/$configContents/gr;
于 2013-02-19T16:39:16.207 回答