Regex Unicode 笔记 - yanbin's Blog

Regex Unicode 笔记

yanbin posted @ 2015年3月17日 18:14 in Programming , 1946 阅读
 
1. Unicode 字符集使用一个或多个 code point 代表一个字符或者说字符映射到特定的数字上。
    
2. 字符又分为基本字符和组合字符。
   一个基本字符与一个或多个组合字符构成组合序列,用来表示一些非ASCII特殊字符。
   比如:
   à 这样的音标符号, 表示为 U+0061 (a) + U+0300 (`) 这两个字符的组合;其中 a 是基本字符,
   ` 是组合字符。
 
3. 一个字符可以被多个代码点表示.
   à 即可表示为: U+0061 和 U+0300 的组合; 为了与 Latin-1 转化方便, à 也表示为 U+00E0,
   很可能是法语单词。也就是说 Unicode 代码点与字符间不是一一映射的关系。
 
4. 考虑三个问题:
   1)程序中的字符串在程序运行时,最终的数据是什么?
     用户不用考虑这样的问题,如果程序支持 Unicode 的话,字符串总是会转化为
     Unicode code point 数字存储, 无论其原来的编码是什么。
     这与编辑器是有关系的,程序中的字符串是用编辑器输入并存储的,无论程序是在编译时还是
     运行时转换这些字符串为 Unicode, 总是读入特定编码的字符串,然后解码为 Unicode,
     关键是如果判定这些字符串的编码的呢?
 
   2)程序运行时从标准输入读到字符串,最终的数据是什么?
     这个首先与程序从那里读入有关,终端吗?那就是要看终端使用的字符集(编码)是什么了,
     这影响终端的输入和打印。
     不同的终端可能不同,当然可以配置,比如:gnome-Timinal Timinitor, konsole;
     就算是从控制台对入字符串,控制台也是可以配置字符编码的。
 
   3)程序运行时从文件读到字符串,最终的数据又是什么呢?
     这个当然与文件的内容有关,与用什么编辑器编辑的文件有关,与文件的内容是如何填充的有关,
     关键是一个程序是如何识别编码的?
     上面三个问题至少可以明白一件事:
     在支持 Unicode 的程序中,要用正则表达式处理 Unicode 格式的字符串。
    
5. Unicode 组合字符序列的匹配. \X
   这个相当于' . ', dot, 用来匹配任意 Unicode 字符,包括换行符和终结符。
   在 Perl, PHP 中 \X 缩略表示 \P{M}\p{M}*, 匹配一个基本字符(除p{M} 之外的任何字符),
   之后可能有任意数目的组合字符(除\p{M} 之外), \p{M},\p{Mark} 是 Unicode 的一个属性分类,
   正是组合字符所属分类.
Avatar_small
delete hotmail accou 说:
2019年6月05日 12:21

It is fantastic experience to learn how to delete hotmail account by this site.

Avatar_small
reese 说:
2022年11月29日 00:09

Unicode is a standard for encoding characters that allows for a consistent representation of text across different devices and platforms. In Python, Unicode objects are represented as strings. Regexes work with Unicode strings in Python just as they do with regular strings. However, there are a few things to keep in mind when working with real estate consultant Orlando Unicode regexes. First, make sure that your regex is compiled with the UNICODE flag. This flag tells the regex engine to treat the pattern as a sequence of Unicode code points, rather than a sequence of bytes.

Avatar_small
charlly 说:
2022年12月18日 15:42

The Unicode standard provides a unique number for every character, no matter what the platform, program, or language. Cannabidiol CBD products regex Unicode notes are designed to help you work with Unicode characters in regular expressions.

Avatar_small
emma 说:
2022年12月19日 22:00

"There are a few things to keep in mind when using regular expressions with Unicode: - When specifying a range of characters, be sure to use the correct Unicode character properties. For example, \p{L} will match any letter, whether it's ASCII or not. - To match a specific Unicode character, use the \u escape sequence. For example, to match the letter á, use the pattern \u00E1. - Some characters have multiple Unicode representations. For example, the character é can be represented as either \u00E9 or cbd benefits \u0065\u0301. To match both representations, use the \C escape sequence. - Some Unicode characters represent multiple code points."


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee