Back to index

python3.2  3.2.2
Classes | Functions | Variables
re Namespace Reference

Classes

class  Scanner

Functions

def match
def search
def sub
def subn
def split
def findall
def finditer
def compile
def purge
def template
def escape
def _compile
def _compile_typed
def _compile_repl
def _expand
def _subx
def _pickle

Variables

list __all__
string __version__ = "2.2.1"
 A = ASCIIsre_compile.SRE_FLAG_ASCII
 I = IGNORECASEsre_compile.SRE_FLAG_IGNORECASE
 L = LOCALEsre_compile.SRE_FLAG_LOCALE
 U = UNICODEsre_compile.SRE_FLAG_UNICODE
 M = MULTILINEsre_compile.SRE_FLAG_MULTILINE
 S = DOTALLsre_compile.SRE_FLAG_DOTALL
 X = VERBOSEsre_compile.SRE_FLAG_VERBOSE
 T = TEMPLATEsre_compile.SRE_FLAG_TEMPLATE
 DEBUG = sre_compile.SRE_FLAG_DEBUG
 error = sre_compile.error
tuple _alphanum_str
tuple _alphanum_bytes
tuple _pattern_type = type(sre_compile.compile("", 0))

Function Documentation

def re._compile (   pattern,
  flags 
) [private]

Definition at line 254 of file re.py.

00254 
00255 def _compile(pattern, flags):
00256     return _compile_typed(type(pattern), pattern, flags)
00257 
@functools.lru_cache(maxsize=500)

Here is the call graph for this function:

Here is the caller graph for this function:

def re._compile_repl (   repl,
  pattern 
) [private]

Definition at line 270 of file re.py.

00270 
00271 def _compile_repl(repl, pattern):
00272     # internal: compile replacement pattern
00273     return sre_parse.parse_template(repl, pattern)

Here is the call graph for this function:

Here is the caller graph for this function:

def re._compile_typed (   text_bytes_type,
  pattern,
  flags 
) [private]

Definition at line 258 of file re.py.

00258 
00259 def _compile_typed(text_bytes_type, pattern, flags):
00260     # internal: compile pattern
00261     if isinstance(pattern, _pattern_type):
00262         if flags:
00263             raise ValueError(
00264                 "Cannot process flags argument with a compiled pattern")
00265         return pattern
00266     if not sre_compile.isstring(pattern):
00267         raise TypeError("first argument must be string or compiled pattern")
00268     return sre_compile.compile(pattern, flags)
00269 
@functools.lru_cache(maxsize=500)

Here is the call graph for this function:

Here is the caller graph for this function:

def re._expand (   pattern,
  match,
  template 
) [private]

Definition at line 274 of file re.py.

00274 
00275 def _expand(pattern, match, template):
00276     # internal: match.expand implementation hook
00277     template = sre_parse.parse_template(template, pattern)
00278     return sre_parse.expand_template(template, match)

Here is the call graph for this function:

def re._pickle (   p) [private]

Definition at line 293 of file re.py.

00293 
00294 def _pickle(p):
00295     return _compile, (p.pattern, p.flags)
00296 
00297 copyreg.pickle(_pattern_type, _pickle, _compile)
00298 
00299 # --------------------------------------------------------------------
00300 # experimental stuff (see python-dev discussions for details)

Here is the call graph for this function:

def re._subx (   pattern,
  template 
) [private]

Definition at line 279 of file re.py.

00279 
00280 def _subx(pattern, template):
00281     # internal: pattern.sub/subn implementation helper
00282     template = _compile_repl(template, pattern)
00283     if not template[0] and len(template[1]) == 1:
00284         # literal replacement
00285         return template[1][0]
00286     def filter(match, template=template):
00287         return sre_parse.expand_template(template, match)
00288     return filter
00289 
00290 # register myself for pickling

Here is the call graph for this function:

def re.compile (   pattern,
  flags = 0 
)

Definition at line 204 of file re.py.

00204 
00205 def compile(pattern, flags=0):
00206     "Compile a regular expression pattern, returning a pattern object."
00207     return _compile(pattern, flags)

Here is the call graph for this function:

def re.escape (   pattern)

Definition at line 222 of file re.py.

00222 
00223 def escape(pattern):
00224     "Escape all non-alphanumeric characters in pattern."
00225     if isinstance(pattern, str):
00226         alphanum = _alphanum_str
00227         s = list(pattern)
00228         for i, c in enumerate(pattern):
00229             if c not in alphanum:
00230                 if c == "\000":
00231                     s[i] = "\\000"
00232                 else:
00233                     s[i] = "\\" + c
00234         return "".join(s)
00235     else:
00236         alphanum = _alphanum_bytes
00237         s = []
00238         esc = ord(b"\\")
00239         for c in pattern:
00240             if c in alphanum:
00241                 s.append(c)
00242             else:
00243                 if c == 0:
00244                     s.extend(b"\\000")
00245                 else:
00246                     s.append(esc)
00247                     s.append(c)
00248         return bytes(s)
00249 
00250 # --------------------------------------------------------------------
00251 # internals

Here is the call graph for this function:

Here is the caller graph for this function:

def re.findall (   pattern,
  string,
  flags = 0 
)
Return a list of all non-overlapping matches in the string.

If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern
has more than one group.

Empty matches are included in the result.

Definition at line 185 of file re.py.

00185 
00186 def findall(pattern, string, flags=0):
00187     """Return a list of all non-overlapping matches in the string.
00188 
00189     If one or more groups are present in the pattern, return a
00190     list of groups; this will be a list of tuples if the pattern
00191     has more than one group.
00192 
00193     Empty matches are included in the result."""
00194     return _compile(pattern, flags).findall(string)

Here is the call graph for this function:

Here is the caller graph for this function:

def re.finditer (   pattern,
  string,
  flags = 0 
)
Return an iterator over all non-overlapping matches in the
string.  For each match, the iterator returns a match object.

Empty matches are included in the result.

Definition at line 197 of file re.py.

00197 
00198     def finditer(pattern, string, flags=0):
00199         """Return an iterator over all non-overlapping matches in the
00200         string.  For each match, the iterator returns a match object.
00201 
00202         Empty matches are included in the result."""
00203         return _compile(pattern, flags).finditer(string)

Here is the call graph for this function:

Here is the caller graph for this function:

def re.match (   pattern,
  string,
  flags = 0 
)
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.

Definition at line 150 of file re.py.

00150 
00151 def match(pattern, string, flags=0):
00152     """Try to apply the pattern at the start of the string, returning
00153     a match object, or None if no match was found."""
00154     return _compile(pattern, flags).match(string)

Here is the call graph for this function:

def re.purge ( )

Definition at line 208 of file re.py.

00208 
00209 def purge():
00210     "Clear the regular expression caches"
00211     _compile_typed.cache_clear()
00212     _compile_repl.cache_clear()

Here is the caller graph for this function:

def re.search (   pattern,
  string,
  flags = 0 
)
Scan through string looking for a match to the pattern, returning
a match object, or None if no match was found.

Definition at line 155 of file re.py.

00155 
00156 def search(pattern, string, flags=0):
00157     """Scan through string looking for a match to the pattern, returning
00158     a match object, or None if no match was found."""
00159     return _compile(pattern, flags).search(string)

Here is the call graph for this function:

Here is the caller graph for this function:

def re.split (   pattern,
  string,
  maxsplit = 0,
  flags = 0 
)
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings.

Definition at line 180 of file re.py.

00180 
00181 def split(pattern, string, maxsplit=0, flags=0):
00182     """Split the source string by the occurrences of the pattern,
00183     returning a list containing the resulting substrings."""
00184     return _compile(pattern, flags).split(string, maxsplit)

Here is the call graph for this function:

Here is the caller graph for this function:

def re.sub (   pattern,
  repl,
  string,
  count = 0,
  flags = 0 
)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl.  repl can be either a string or a callable;
if a string, backslash escapes in it are processed.  If it is
a callable, it's passed the match object and must return
a replacement string to be used.

Definition at line 160 of file re.py.

00160 
00161 def sub(pattern, repl, string, count=0, flags=0):
00162     """Return the string obtained by replacing the leftmost
00163     non-overlapping occurrences of the pattern in string by the
00164     replacement repl.  repl can be either a string or a callable;
00165     if a string, backslash escapes in it are processed.  If it is
00166     a callable, it's passed the match object and must return
00167     a replacement string to be used."""
00168     return _compile(pattern, flags).sub(repl, string, count)

Here is the call graph for this function:

Here is the caller graph for this function:

def re.subn (   pattern,
  repl,
  string,
  count = 0,
  flags = 0 
)
Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
string by the replacement repl.  number is the number of
substitutions that were made. repl can be either a string or a
callable; if a string, backslash escapes in it are processed.
If it is a callable, it's passed the match object and must
return a replacement string to be used.

Definition at line 169 of file re.py.

00169 
00170 def subn(pattern, repl, string, count=0, flags=0):
00171     """Return a 2-tuple containing (new_string, number).
00172     new_string is the string obtained by replacing the leftmost
00173     non-overlapping occurrences of the pattern in the source
00174     string by the replacement repl.  number is the number of
00175     substitutions that were made. repl can be either a string or a
00176     callable; if a string, backslash escapes in it are processed.
00177     If it is a callable, it's passed the match object and must
00178     return a replacement string to be used."""
00179     return _compile(pattern, flags).subn(repl, string, count)

Here is the call graph for this function:

Here is the caller graph for this function:

def re.template (   pattern,
  flags = 0 
)

Definition at line 213 of file re.py.

00213 
00214 def template(pattern, flags=0):
00215     "Compile a template pattern, returning a pattern object"
00216     return _compile(pattern, flags|T)

Here is the call graph for this function:


Variable Documentation

list re.__all__
Initial value:
00001 [ "match", "search", "sub", "subn", "split", "findall",
00002     "compile", "purge", "template", "escape", "A", "I", "L", "M", "S", "X",
00003     "U", "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
00004     "UNICODE", "error" ]

Definition at line 124 of file re.py.

Definition at line 129 of file re.py.

Initial value:
00001 frozenset(
00002     b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")

Definition at line 219 of file re.py.

Initial value:
00001 frozenset(
00002     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890")

Definition at line 217 of file re.py.

Definition at line 252 of file re.py.

re.A = ASCIIsre_compile.SRE_FLAG_ASCII

Definition at line 132 of file re.py.

re.DEBUG = sre_compile.SRE_FLAG_DEBUG

Definition at line 142 of file re.py.

Definition at line 145 of file re.py.

Definition at line 133 of file re.py.

Definition at line 134 of file re.py.

Definition at line 136 of file re.py.

Definition at line 137 of file re.py.

Definition at line 141 of file re.py.

Definition at line 135 of file re.py.

Definition at line 138 of file re.py.