我试图用单引号或双引号替换各种字符。大型Unicode代码点上的Perl正则表达式匹配
这里是我的测试文件:
# Replace all with double quotes
" fullwidth
“ left
” right
„ low
" normal
# Replace all with single quotes
' normal
‘ left
’ right
‚ low
‛ reverse
` backtick
我试图做到这一点...
perl -Mutf8 -pi -e "s/[\x{2018}\x{201A}\x{201B}\x{FF07}\x{2019}\x{60}]/'/ug" test.txt
perl -Mutf8 -pi -e 's/[\x{FF02}\x{201C}\x{201D}\x{201E}]/"/ug' text.txt
但只有反引号字符被正确更换。我认为它与其他代码点太大有关,但我无法找到任何文档。
这里我有一个one-liner转储的Unicode代码点,以验证它们符合我的正则表达式。
$ awk -F\ '{print $1}' test.txt | \
perl -C7 -ne 'for(split(//)){print sprintf("U+%04X", ord)." ".$_."\n"}'
U+FF02 "
U+201C “
U+201D ”
U+201E „
U+0022 "
U+0027 '
U+2018 ‘
U+2019 ’
U+201A ‚
U+201B ‛
U+0060 `
为什么我的正则表达式不匹配?
非常感谢。 –
@tchrist,请通过将-CSAD替换为-CSD来更正您的答案。我没有编辑权力这样做。 –
@HansDeragon完成。 – tchrist