Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何替换所有£;在与&;英镑用Perl?_Regex_Perl - Fatal编程技术网

Regex 如何替换所有£;在与&;英镑用Perl?

Regex 如何替换所有£;在与&;英镑用Perl?,regex,perl,Regex,Perl,我正在尝试将HTML文件中的所有符号替换为£。我的正则表达式似乎不起作用 你能帮忙吗?你很可能忘了: use utf8; 请尝试以下程序: #!/usr/bin/perl use strict; use warnings; use utf8; while (<DATA>) { s/£/&pound;/g; print } __END__ This is sample text with lots of £££! 50£ is better t

我正在尝试将HTML文件中的所有
符号替换为
£。我的正则表达式似乎不起作用


你能帮忙吗?

你很可能忘了:

use utf8;
请尝试以下程序:

#!/usr/bin/perl

use strict;
use warnings;
use utf8;

while (<DATA>) {
    s/£/&pound;/g;
    print
}

__END__
This is sample text with lots of £££!
50£ is better than 0£.
这应该行得通

#!/usr/bin/perl
# File: convert.pl
no utf8; # its not required
while (<>) {
    s/(\xa3)/pound/g;
        print;
}
就说

chmod a+x convert.pl
convert.pl yourfile.html > newfile.html

为什么?;英镑而不仅仅是“£;”在替换中?如果您使用&;结果将是英镑;而不是浏览器中的%。@Lars Haugseth:问题后来被编辑为更改
&;磅
£。我已经编辑过了。谢谢你让我知道。:-)@克丽什:对不起,我不明白你想做什么。请解释。我可以在vi编辑器中查找和替换。问题是什么issue@Krish当前位置我还是不明白你在说什么。是的,您可以使用
vi
查找和替换。你到底想做什么?展示你尝试过但没有成功的东西,让人们看到哪里出了问题并帮助你?你不断在评论中问“问题出在哪里”,但没有人能告诉你,因为你没有说你做了什么。你想在Vim里做这个吗?如果是,怎么做?您正在尝试使用Perl来实现这一点吗?如果是,怎么做?对不起,是mitake,在此之前我插入其他评论并删除它。问题解决了now@Krish:请养成不删除他人回复的评论的习惯。否则,回复评论看起来就不合适了。如果只是在末尾打印,那么应该使用-p标志而不是-n
perl-i.bak-pe's/£/£/g'文件
#!/usr/bin/perl
while (<>) {
    s/£/pound/g;
        print;
}
chmod a+x convert.pl
convert.pl yourfile.html > newfile.html
perl -i.bak -ne 's/£/&pound/g; print $_' file