为什么Ruby/[[:: punct:]]/会错过一些标点符号? [英] Why does Ruby /[[:punct:]]/ miss some punctuation characters?

查看:295
本文介绍了为什么Ruby/[[:: punct:]]/会错过一些标点符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby /[[:punct:]]/应该匹配所有标点符号".根据 Wikipedia 的说法,这表示每个POSIX标准为/[\]\[!"#$%&'()*+,./:;<=>?@\^_`{|}~-]/.

Ruby /[[:punct:]]/ is supposed to match all "punctuation characters". According to Wikipedia, this means /[\]\[!"#$%&'()*+,./:;<=>?@\^_`{|}~-]/ per POSIX standard.

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

但是,它与不匹配:=`~$^+|<>(至少在ruby 1.9.3p194中).

However, it does not match: =`~$^+|<> (at least in ruby 1.9.3p194).

有什么作用?

推荐答案

标点符号类由语言环境定义.开放小组对打孔的LC_TYPE定义说:

The punctuation character class is defined by the locale. The Open Group LC_TYPE definition for punct says:

定义要归类为标点符号的字符.在POSIX语言环境中,<space>或类alpha,digit或cntrl中的任何字符均不应包含在内.在语言环境定义文件中,没有为关键字"upper","lower","alpha","digit","cntrl","xdigit"或."指定任何字符.

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 的方法,但实际上并没有直接定义标点符号-这是语言环境的工作.

Basically, it defines how punct can be defined by exluding other character classes, but it doesn't actually define the punctuation symbols directly--that's the locale's job.

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

I couldn't find a canonical reference to what is in each locale. Maybe someone else knows. Meanwhile, you can find an LC_TYPE that matches the punct character class you want, or just specify the class directly.

这篇关于为什么Ruby/[[:: punct:]]/会错过一些标点符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆