我試圖用單引號或雙引號替換各種字符。大型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