本文介绍了为什么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:

基本上,它定义了如何通过合并其他字符类来定义 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:]]/会错过一些标点符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:59