# 6. Text Processing Services

The modules described in this chapter provide a wide range of string manipulation operations and other text processing services.

The `codecs` module described under Binary Data Services is also highly relevant to text processing. In addition, see the documentation for Python’s built-in string type in Text Sequence Type — str.

- 6.1. `string` — 常见的字符串操作
  - 6.1.1. 字符串常量
  - 6.1.2. Custom String Formatting
  - 6.1.3. Format String Syntax
    - 6.1.3.1. Format Specification Mini-Language
    - 6.1.3.2. Format examples
  - 6.1.4. Template strings
  - 6.1.5. Helper functions
- 6.2. `re` — 正则表达式操作
  - 6.2.1. 正则表达式语法
  - 6.2.2. 模块内容
  - 6.2.3. 正则表达式对象 （正则对象）
  - 6.2.4. 匹配对象
  - 6.2.5. 正则表达式例子
    - 6.2.5.1. 检查对子
    - 6.2.5.2. 模拟 scanf()
    - 6.2.5.3. search() vs. match()
    - 6.2.5.4. 建立一个电话本
    - 6.2.5.5. 文字整理
    - 6.2.5.6. 找到所有副词
    - 6.2.5.7. 找到所有副词和位置
    - 6.2.5.8. 原始字符记法
    - 6.2.5.9. 写一个词法分析器
- 6.3. `difflib` — Helpers for computing deltas
  - 6.3.1. SequenceMatcher Objects
  - 6.3.2. SequenceMatcher Examples
  - 6.3.3. Differ Objects
  - 6.3.4. Differ Example
  - 6.3.5. A command-line interface to difflib
- 6.4. `textwrap` — Text wrapping and filling
- 6.5. `unicodedata` — Unicode Database
- 6.6. `stringprep` — Internet String Preparation
- 6.7. `readline` — GNU readline interface
  - 6.7.1. Init file
  - 6.7.2. Line buffer
  - 6.7.3. History file
  - 6.7.4. History list
  - 6.7.5. Startup hooks
  - 6.7.6. Completion
  - 6.7.7. 示例
- 6.8. `rlcompleter` — Completion function for GNU readline
  - 6.8.1. Completer Objects