除非重复一次,否则从字符串中删除特定字符的最干净/最简单的方法是什么。
例如给定以下字符串:
'it''s 'simple'
我预计:
it's simple
对于我的用法,一行中的 ' 字符永远不会超过两个。
使用否定的前瞻断言。
#!/use/bin/perl
use strict;
use warnings;
use feature 'say';
$_ = "'it''s simple'";
say;
s/'(?!')//g;
say;
'(?!')
意思是“一个单引号后面没有紧跟着另一个单引号”。
输出:
'it''s simple'
it's simple
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句