珀尔 | quotemeta()函数
Perl 中的 quotemeta()函数转义作为参数传递给它的值中的所有元字符。
例子:
Input : "GF*..G"
Output : "GF\*\.\.G"
Syntax: quotemeta(value)
Parameter:
value: String containing meta-characters
Return:
a string with all meta-characters escaped
示例 1:
#!/usr/bin/perl -w
$string = "GF*\n[.]*G";
print "Original String: \n";
print $string;
# Applying operation on the String
print "\n\nString after operation: \n";
print quotemeta($string);
输出:
Original String:
GF*
[.]*G
String after operation:
GF\*\
\[\.\]\*G
示例 2:
#!/usr/bin/perl -w
$string = "GF+n\{.}/G";
print "Original String: \n";
print $string;
# Applying operation on the String
print "\n\nString after operation: \n";
print quotemeta($string);
输出:
Original String:
GF+n{.}/G
String after operation:
GF\+n\{\.\}\/G