1. Computing

Pythons 're' Module: Regular Expression Objects

Methods and Attributes of Regular Expression Objects

From , former About.com Guide

Using the compile() function, one compiles a regular expression into a regular expression object and (usually) assigns it to a value. The methods and attributes of such regular expression objects are as follows ("regex" is here used as the object handler):

  • regex.match(string[, start-position [, end-position]]): Similar to the match() function but allows you to indicate a start position and an end position for the matching.
  • regex.search(string [, start-position] [, end-position]): Similar to the search() function but allows the limitation of searching to be within two points within string.
  • regex.split(string[, maxsplit = 0]): Same as the split() function.
  • regex.findall(string[, start-position [, end-position]]): Identical to the findall() function except that it allows limitations within the string.
  • regex.finditer(string[, start-position[, end-position]]): Identical to the dall() function except that it allows limitations within the string.
  • regex.sub(replacement, string [, count = 0]): Same as the sub() function.
  • regex.subn(replacement, string [, count = 0]): Same as the subn() function.
  • regex.flags: The flags used when compiling the regular expression object.
  • regex.groupindex: A dictionary mapping of any symbolic group names defined by r'(?P<id>' to group numbers. If no symbolic groups were used in the pattern, the dictionary is empty.
  • regex.pattern: The pattern from which the regular expression object was compiled.
  1. About.com
  2. Computing
  3. Python
  4. Regular Expressions
  5. Python Library - Python Regular Expressions - RE Object Methods and Attributes

©2013 About.com. All rights reserved.