gpt4 book ai didi

ruby - 为什么 Ruby/[[ :punct:]]/miss some punctuation characters?

转载 作者:数据小太阳 更新时间:2023-10-29 06:39:31 24 4
gpt4 key购买 nike

ruby /[[:punct:]]/应该匹配所有“标点字符”。根据Wikipedia , 这意味着 /[\]\[!"#$%&'()*+,./:;<=>?@\^_`{|}~-]/根据 POSIX 标准。

匹配:-[]\;',./!@#%&*()_{}::"? .

但是,它匹配:=`~$^+|<> (至少在 ruby​​ 1.9.3p194 中是这样)。

什么给了?

最佳答案

标点字符类由语言环境定义。公开组LC_TYPE definition for punct说:

Define characters to be classified as punctuation characters. In the POSIX locale, neither the <space> nor any characters in classes alpha, digit, or cntrl shall be included. In a locale definition file, no character specified for the keywords upper, lower, alpha, digit, cntrl, xdigit, or as the shall be specified.

基本上,它定义了如何通过排除其他字符类来定义 punct,但实际上并没有直接定义标点符号——那是语言环境的工作。

我找不到每个语言环境中的规范引用。也许别人知道。同时,您可以找到与您想要的 punct 字符类匹配的 LC_TYPE,或者直接指定类。

关于ruby - 为什么 Ruby/[[ :punct:]]/miss some punctuation characters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11130490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com