[英]Search and replace a string having special characters in a file using Perl
Search and replace a string in a file using Perl.使用 Perl 搜索和替换文件中的字符串。 I have a .txt file.
我有一个 .txt 文件。 where i need to search and replace a string.
我需要搜索和替换字符串的地方。 i code i have is working fine for string not having special characters.but for the string containing special characters like (?,=,:: ) is not working with this code.
我的代码对于没有特殊字符的字符串工作正常。但是对于包含特殊字符(如 (?,=,:: ) 的字符串)不适用于此代码。
Problem statement image问题陈述图片
Code i am using and expected results我正在使用的代码和预期结果
Use Perl's built-in function quotemeta
to escape all special characters in your search string.使用 Perl 的内置函数
quotemeta
来转义搜索字符串中的所有特殊字符。 See https://perldoc.perl.org/functions/quotemeta.html见https://perldoc.perl.org/functions/quotemeta.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.