Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:4.1 stringUp:4. String ServicesNext:4.2.1 Regular Expression Syntax

4.2re -- Regular expression operations

This module provides regular expression matching operations similar tothose found in Perl. Regular expression pattern strings may notcontain null bytes, but can specify the null byte using the\number notation. Both patterns and strings to besearched can be Unicode strings as well as 8-bit strings. There module is always available.

Regular expressions use the backslash character ("\") toindicate special forms or to allow special characters to be usedwithout invoking their special meaning. This collides with Python'susage of the same character for the same purpose in string literals;for example, to match a literal backslash, one might have to write'\\\\' as the pattern string, because the regular expressionmust be "\\", and each backslash must be expressed as"\\" inside a regular Python string literal.

The solution is to use Python's raw string notation for regularexpression patterns; backslashes are not handled in any special way ina string literal prefixed with "r". Sor"\n" is atwo-character string containing "\" and "n",while"\n" is a one-character string containing a newline.Usually patterns will be expressed in Python code using this rawstring notation.

Implementation note:There module has two distinctimplementations:sre is the default implementation andincludes Unicode support, but may run into stack limitations for somepatterns. Though this will be fixed for a future release of Python,the older implementation (without Unicode support) is still availableas thepre module.

See Also:

Mastering Regular Expressions
Book on regular expressions by Jeffrey Friedl, published by O'Reilly. The Python material in this book dates from before there module, but it covers writing good regular expression patterns in great detail.


Subsections


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:4.1 stringUp:4. String ServicesNext:4.2.1 Regular Expression Syntax
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp