我试过的PCRE Regex找到了第一个字符并删除了其后的所有内容。
以下是字符串示例:
$128.48 One Month TV Internet and Voice, 100GB of Fiber<sup>†</sup> Internet.
$148.48 One Month TV Internet and Voice, 200GB of Fiber<sup>†</sup> Internet and a free movie rental from MoviePlex.
我想从String中提取以下字符,并保持String的其余部分不变。摘录:<sup>&dagger </sup>
预期结果:
$148.48 One Month TV Internet and Voice, 200GB of Fiber;Internet and a free movie rental from MoviePlex.
$128.48 One Month TV Internet and Voice, 100GB of Fiber; Internet.
这是我试过的正则表达式:
[^&dagger<sup><\/sup>]*
答案 0 :(得分:0)
That's how you could do this in Perl:
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Data::Dumper;
my @strings = (
'$128.48 One Month TV Internet and Voice, 100GB of Fiber<sup>†</sup> Internet.',
'$148.48 One Month TV Internet and Voice, 200GB of Fiber<sup>†</sup> Internet and a free movie rental from MoviePlex.'
);
my @updated_strings = map { my $str = $_; $str =~ s/<sup>.+?<\/sup>/;/; $str; } @strings;
print 'UPDATED: ' . Dumper(\@updated_strings) . "\n";
你也可以在语言无关的regex101.com中使用它:example