home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / r / regsub < prev    next >
Text File  |  1996-11-14  |  3KB  |  49 lines

  1. <TITLE>regsub -- Python library reference</TITLE>
  2. Next: <A HREF="../s/struct" TYPE="Next">struct</A>  
  3. Prev: <A HREF="../r/regex" TYPE="Prev">regex</A>  
  4. Up: <A HREF="../s/string_services" TYPE="Up">String Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>4.3. Standard Module <CODE>regsub</CODE></H1>
  7. This module defines a number of functions useful for working with
  8. regular expressions (see built-in module <CODE>regex</CODE>).
  9. <P>
  10. Warning: these functions are not thread-safe.
  11. <P>
  12. <DL><DT><B>sub</B> (<VAR>pat</VAR>, <VAR>repl</VAR>, <VAR>str</VAR>) -- function of module regsub<DD>
  13. Replace the first occurrence of pattern <VAR>pat</VAR> in string
  14. <VAR>str</VAR> by replacement <VAR>repl</VAR>.  If the pattern isn't found,
  15. the string is returned unchanged.  The pattern may be a string or an
  16. already compiled pattern.  The replacement may contain references
  17. `<SAMP>\<VAR>digit</VAR></SAMP>' to subpatterns and escaped backslashes.
  18. </DL>
  19. <DL><DT><B>gsub</B> (<VAR>pat</VAR>, <VAR>repl</VAR>, <VAR>str</VAR>) -- function of module regsub<DD>
  20. Replace all (non-overlapping) occurrences of pattern <VAR>pat</VAR> in
  21. string <VAR>str</VAR> by replacement <VAR>repl</VAR>.  The same rules as for
  22. <CODE>sub()</CODE> apply.  Empty matches for the pattern are replaced only
  23. when not adjacent to a previous match, so e.g.
  24. <CODE>gsub('', '-', 'abc')</CODE> returns <CODE>'-a-b-c-'</CODE>.
  25. </DL>
  26. <DL><DT><B>split</B> (<VAR>str</VAR>, <VAR>pat</VAR>[, <VAR>maxsplit</VAR>]) -- function of module regsub<DD>
  27. Split the string <VAR>str</VAR> in fields separated by delimiters matching
  28. the pattern <VAR>pat</VAR>, and return a list containing the fields.  Only
  29. non-empty matches for the pattern are considered, so e.g.
  30. <CODE>split('a:b', ':*')</CODE> returns <CODE>['a', 'b']</CODE> and
  31. <CODE>split('abc', '')</CODE> returns <CODE>['abc']</CODE>.  The <VAR>maxsplit</VAR>
  32. defaults to 0. If it is nonzero, only <VAR>maxsplit</VAR> number of splits
  33. occur, and the remainder of the string is returned as the final
  34. element of the list.
  35. </DL>
  36. <DL><DT><B>splitx</B> (<VAR>str</VAR>, <VAR>pat</VAR>[, <VAR>maxsplit</VAR>]) -- function of module regsub<DD>
  37. Split the string <VAR>str</VAR> in fields separated by delimiters matching
  38. the pattern <VAR>pat</VAR>, and return a list containing the fields as well
  39. as the separators.  For example, <CODE>splitx('a:::b', ':*')</CODE> returns
  40. <CODE>['a', ':::', 'b']</CODE>.  Otherwise, this function behaves the same
  41. as <CODE>split</CODE>.
  42. </DL>
  43. <DL><DT><B>capwords</B> (<VAR>s</VAR>[, <VAR>pat</VAR>]) -- function of module regsub<DD>
  44. Capitalize words separated by optional pattern <VAR>pat</VAR>.  The default
  45. pattern uses any characters except letters, digits and underscores as
  46. word delimiters.  Capitalization is done by changing the first
  47. character of each word to upper case.
  48. </DL>
  49.