如何从perl中的字符串中删除\ r \ n和\

时间:2013-05-07 18:22:37

标签: perl

我需要从一个大的$ string中删除每个\ r \ n和\的顺序,我该如何实现呢?

示例字符串:

$string = '\/9jAAMAAAAB\r\nAAEAAABAAAD\/2'

需要它看起来像这样:

$string = '/9jAAMAAAABAAEAAABAAAD/2'

3 个答案:

答案 0 :(得分:2)

#!/usr/bin/perl
$string = "something\\r\\n\\";
$string =~ s/(\\r)|(\\n)|(\\)//g;
print $string;

=> something

答案 1 :(得分:1)

这是另一种选择:

use strict;
use warnings;

my $string = '\/9jAAMAAAAB\r\nAAEAAABAAAD\/2';
$string =~ s!\\[rn]?!!g;
print $string;

输出:

/9jAAMAAAABAAEAAABAAAD/2

答案 2 :(得分:0)

这是一种方法:

$new_string = $string =~ s/\\|\R//g;
print "$new_string";