我是个正则表达式(Regular Expressions)迷。在编写用于查找没有结尾标点的节(verse)的正则表达式时:
[^\\][^\p{P}\d]\r\n\\v
或者
[^\\l][^\p{P}\d]\r\n\\v \d+ \p{Lu}
,我意识到 RegexPal(以及 FLEx 的过滤/处理功能)中 C# 风格的正则表达式支持简写(而非长写)的 Unicode 字符类别。
其中一些最有用的是:
\p{L} 字母(几乎适用于任何正字法)
\p{Lu} 大写字母
\p{Ll} 小写字母
\p{P} 标点符号
\p{M} 任何变音符号
如果斜杠后的 P 是大写的,则表示“非”该字符类别。
完整列表:
\p{L}:任何语言的任何类型的字母。
\p{Ll}:具有大写变体的小写字母。
\p{Lu}:具有小写变体的大写字母。
\p{Lt}:当单词仅首字母大写时,出现在单词开头的字母。
\p{L&}:同时存在小写和大写变体的字母(Ll、Lu 和 Lt 的组合)。
\p{Lm}:像字母一样使用的特殊字符。
\p{Lo}:没有小写和大写变体的字母或表意文字。
\p{M}:旨在与其他字符组合使用的字符(例如重音符号、变音符、包围框等)。
\p{Mn}:旨在与其他字符组合使用且不占用额外空间的字符(例如重音符号、变音符等)。
\p{Mc}:旨在与其他字符组合使用且占用额外空间的字符(许多东方语言中的元音符号)。
\p{Me}:包围其组合字符的字符(圆圈、方框、键帽等)。
\p{Z}:任何类型的空白或不可见分隔符。
\p{Zs}:不可见但占用空间的空白字符。
\p{Zl}:行分隔符字符 U+2028。
\p{Zp}:段落分隔符字符 U+2029。
\p{S}:数学符号、货币符号、装饰符号、制表符等。
\p{Sm}:任何数学符号。
\p{Sc}:任何货币符号。
\p{Sk}:作为独立完整字符使用的组合字符(标记)。
\p{So}:各种非数学符号、非货币符号或非组合字符的符号。
\p{N}:任何文字系统中的任何类型的数字字符。
\p{Nd}:除表意文字系统外,任何文字系统中的数字零到九。
\p{Nl}:看起来像字母的数字,例如罗马数字。
\p{No}:上标或下标数字,或非 0–9 的数字(不包括表意文字系统中的数字)。
\p{P}:任何类型的标点符号字符。
\p{Pd}:任何类型的连字符或破折号。
\p{Ps}:任何类型的开括号。
\p{Pe}:任何类型的闭括号。
\p{Pi}:任何类型的开引号。
\p{Pf}:任何类型的闭引号。
\p{Pc}:连接单词的标点符号字符,如下划线。
\p{Po}:任何非破折号、非括号、非引号或非连接符的标点符号字符。
\p{C}:不可见的控制字符和未使用的码点。
\p{Cc}:ASCII 或 Latin-1 控制字符:0x00–0x1F 和 0x7F–0x9F。
\p{Cf}:不可见的格式指示符。
\p{Co}:任何保留供私有使用的码点。
\p{Cs}:UTF-16 编码中代理对的一半。
\p{Cn}:任何未分配字符的码点。
完整文档:
https://www.regular-expressions.info/unicode.html#category
I’m a Regular Expressions nerd. While I was writing a regex to look for verses with no ending punctuation:
[^\\][^\p{P}\d]\r\n\\v
or
[^\\l][^\p{P}\d]\r\n\\v \d+ \p{Lu}
, I realized that the C# flavor of RegEx in RegexPal (and FLEx filtering/Process) supports shorthand (not longhand) Unicode character categories.
Some of the most useful are:
\p{L} Letter (nearly any orthography)
\p{Lu} Uppercase letter
\p{Ll} Lowercase letter
\p{P} Punctuation
\p{M} Any diacritic
If the P after the slash is capital, it means NOT that character class.
The whole list:
\p{L}: any kind of letter from any language.
\p{Ll}: a lowercase letter that has an uppercase variant.
\p{Lu}: an uppercase letter that has a lowercase variant.
\p{Lt}: a letter that appears at the start of a word when only the first letter of the word is capitalized.
\p{L&}: a letter that exists in lowercase and uppercase variants (combination of Ll, Lu and Lt).
\p{Lm}: a special character that is used like a letter.
\p{Lo}: a letter or ideograph that does not have lowercase and uppercase variants.
\p{M}: a character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.).
\p{Mn}: a character intended to be combined with another character without taking up extra space (e.g. accents, umlauts, etc.).
\p{Mc}: a character intended to be combined with another character that takes up extra space (vowel signs in many Eastern languages).
\p{Me}: a character that encloses the character it is combined with (circle, square, keycap, etc.).
\p{Z}: any kind of whitespace or invisible separator.
\p{Zs}: a whitespace character that is invisible, but does take up space.
\p{Zl}: line separator character U+2028.
\p{Zp}: paragraph separator character U+2029.
\p{S}: math symbols, currency signs, dingbats, box-drawing characters, etc.
\p{Sm}: any mathematical symbol.
\p{Sc}: any currency sign.
\p{Sk}: a combining character (mark) as a full character on its own.
\p{So}: various symbols that are not math symbols, currency signs, or combining characters.
\p{N}: any kind of numeric character in any script.
\p{Nd}: a digit zero through nine in any script except ideographic scripts.
\p{Nl}: a number that looks like a letter, such as a Roman numeral.
\p{No}: a superscript or subscript digit, or a number that is not a digit 0–9 (excluding numbers from ideographic scripts).
\p{P}: any kind of punctuation character.
\p{Pd}: any kind of hyphen or dash.
\p{Ps}: any kind of opening bracket.
\p{Pe}: any kind of closing bracket.
\p{Pi}: any kind of opening quote.
\p{Pf}: any kind of closing quote.
\p{Pc}: a punctuation character such as an underscore that connects words.
\p{Po}: any kind of punctuation character that is not a dash, bracket, quote or connector.
\p{C}: invisible control characters and unused code points.
\p{Cc}: an ASCII or Latin-1 control character: 0x00–0x1F and 0x7F–0x9F.
\p{Cf}: invisible formatting indicator.
\p{Co}: any code point reserved for private use.
\p{Cs}: one half of a surrogate pair in UTF-16 encoding.
\p{Cn}: any code point to which no character has been assigned.
Full Documentation:
https://www.regular-expressions.info/unicode.html#category
机器翻译自 English 显示原文