Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(62519)

Delta Between Two Patch Sets: Doc/library/re.rst

Issue 22578: Add addition attributes to re.error
Left Patch Set: Created 5 years ago
Right Patch Set: Created 5 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/sre_constants.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 :mod:`re` --- Regular expression operations 1 :mod:`re` --- Regular expression operations
2 =========================================== 2 ===========================================
3 3
4 .. module:: re 4 .. module:: re
5 :synopsis: Regular expression operations. 5 :synopsis: Regular expression operations.
6 .. moduleauthor:: Fredrik Lundh <fredrik@pythonware.com> 6 .. moduleauthor:: Fredrik Lundh <fredrik@pythonware.com>
7 .. sectionauthor:: Andrew M. Kuchling <amk@amk.ca> 7 .. sectionauthor:: Andrew M. Kuchling <amk@amk.ca>
8 8
9 9
10 This module provides regular expression matching operations similar to 10 This module provides regular expression matching operations similar to
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 defined by the ``(?P<name>...)`` syntax. ``\g<number>`` uses the correspondin g 694 defined by the ``(?P<name>...)`` syntax. ``\g<number>`` uses the correspondin g
695 group number; ``\g<2>`` is therefore equivalent to ``\2``, but isn't ambiguou s 695 group number; ``\g<2>`` is therefore equivalent to ``\2``, but isn't ambiguou s
696 in a replacement such as ``\g<2>0``. ``\20`` would be interpreted as a 696 in a replacement such as ``\g<2>0``. ``\20`` would be interpreted as a
697 reference to group 20, not a reference to group 2 followed by the literal 697 reference to group 20, not a reference to group 2 followed by the literal
698 character ``'0'``. The backreference ``\g<0>`` substitutes in the entire 698 character ``'0'``. The backreference ``\g<0>`` substitutes in the entire
699 substring matched by the RE. 699 substring matched by the RE.
700 700
701 .. versionchanged:: 3.1 701 .. versionchanged:: 3.1
702 Added the optional flags argument. 702 Added the optional flags argument.
703 703
704 .. versionchanged:: 3.5
705 Unmatched groups are replaced with an empty string.
706
704 707
705 .. function:: subn(pattern, repl, string, count=0, flags=0) 708 .. function:: subn(pattern, repl, string, count=0, flags=0)
706 709
707 Perform the same operation as :func:`sub`, but return a tuple ``(new_string, 710 Perform the same operation as :func:`sub`, but return a tuple ``(new_string,
708 number_of_subs_made)``. 711 number_of_subs_made)``.
709 712
710 .. versionchanged:: 3.1 713 .. versionchanged:: 3.1
711 Added the optional flags argument. 714 Added the optional flags argument.
715
716 .. versionchanged:: 3.5
717 Unmatched groups are replaced with an empty string.
712 718
713 719
714 .. function:: escape(string) 720 .. function:: escape(string)
715 721
716 Escape all the characters in pattern except ASCII letters, numbers and ``'_'` `. 722 Escape all the characters in pattern except ASCII letters, numbers and ``'_'` `.
717 This is useful if you want to match an arbitrary literal string that may 723 This is useful if you want to match an arbitrary literal string that may
718 have regular expression metacharacters in it. 724 have regular expression metacharacters in it.
719 725
720 .. versionchanged:: 3.3 726 .. versionchanged:: 3.3
721 The ``'_'`` character is no longer escaped. 727 The ``'_'`` character is no longer escaped.
722 728
723 729
724 .. function:: purge() 730 .. function:: purge()
725 731
726 Clear the regular expression cache. 732 Clear the regular expression cache.
727 733
728 734
729 .. exception:: error(msg, pattern=None, pos=None) 735 .. exception:: error(msg, pattern=None, pos=None)
730 736
731 Exception raised when a string passed to one of the functions here is not a 737 Exception raised when a string passed to one of the functions here is not a
732 valid regular expression (for example, it might contain unmatched parentheses ) 738 valid regular expression (for example, it might contain unmatched parentheses )
733 or when some other error occurs during compilation or matching. It is never an 739 or when some other error occurs during compilation or matching. It is never an
734 error if a string contains no match for a pattern. The error instance has 740 error if a string contains no match for a pattern. The error instance has
735 the following additional attributes: 741 the following additional attributes:
736 742
737 .. attribute:: msg 743 .. attribute:: msg
738 744
739 The unformatted error message 745 The unformatted error message.
ezio.melotti 2014/10/08 14:58:20 Isn't this equivalent to str(err)? If it is and y
storchaka 2014/10/08 19:36:19 No, this is not equivalent, it doesn't include an
740 746
741 .. attribute:: pattern 747 .. attribute:: pattern
742 748
743 The regular expression pattern. 749 The regular expression pattern.
ezio.melotti 2014/10/08 14:58:20 This is the only sentence with a full stop at the
storchaka 2014/10/08 19:36:19 Indeed. All other sentences are copied from simple
744 750
745 .. attribute:: pos 751 .. attribute:: pos
746 752
747 The index of *pattern* where compilation failed 753 The index of *pattern* where compilation failed.
748 754
749 .. attribute:: lineno 755 .. attribute:: lineno
750 756
751 The line corresponding to *pos* 757 The line corresponding to *pos*.
752 758
753 .. attribute:: colno 759 .. attribute:: colno
754 760
755 The column corresponding to *pos* 761 The column corresponding to *pos*.
756 762
757 .. versionchanged:: 3.5 763 .. versionchanged:: 3.5
758 Added additional attributes. 764 Added additional attributes.
759 765
760 .. _re-objects: 766 .. _re-objects:
761 767
762 Regular Expression Objects 768 Regular Expression Objects
763 -------------------------- 769 --------------------------
764 770
765 Compiled regular expression objects support the following methods and 771 Compiled regular expression objects support the following methods and
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 907
902 .. method:: match.expand(template) 908 .. method:: match.expand(template)
903 909
904 Return the string obtained by doing backslash substitution on the template 910 Return the string obtained by doing backslash substitution on the template
905 string *template*, as done by the :meth:`~regex.sub` method. 911 string *template*, as done by the :meth:`~regex.sub` method.
906 Escapes such as ``\n`` are converted to the appropriate characters, 912 Escapes such as ``\n`` are converted to the appropriate characters,
907 and numeric backreferences (``\1``, ``\2``) and named backreferences 913 and numeric backreferences (``\1``, ``\2``) and named backreferences
908 (``\g<1>``, ``\g<name>``) are replaced by the contents of the 914 (``\g<1>``, ``\g<name>``) are replaced by the contents of the
909 corresponding group. 915 corresponding group.
910 916
917 .. versionchanged:: 3.5
918 Unmatched groups are replaced with an empty string.
911 919
912 .. method:: match.group([group1, ...]) 920 .. method:: match.group([group1, ...])
913 921
914 Returns one or more subgroups of the match. If there is a single argument, t he 922 Returns one or more subgroups of the match. If there is a single argument, t he
915 result is a single string; if there are multiple arguments, the result is a 923 result is a single string; if there are multiple arguments, the result is a
916 tuple with one item per argument. Without arguments, *group1* defaults to zer o 924 tuple with one item per argument. Without arguments, *group1* defaults to zer o
917 (the whole match is returned). If a *groupN* argument is zero, the correspond ing 925 (the whole match is returned). If a *groupN* argument is zero, the correspond ing
918 return value is the entire matching string; if it is in the inclusive range 926 return value is the entire matching string; if it is in the inclusive range
919 [1..99], it is the string matching the corresponding parenthesized group. If a 927 [1..99], it is the string matching the corresponding parenthesized group. If a
920 group number is negative or larger than the number of groups defined in the 928 group number is negative or larger than the number of groups defined in the
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 Token(typ='ID', value='quantity', line=3, column=33) 1419 Token(typ='ID', value='quantity', line=3, column=33)
1412 Token(typ='END', value=';', line=3, column=41) 1420 Token(typ='END', value=';', line=3, column=41)
1413 Token(typ='ID', value='tax', line=4, column=8) 1421 Token(typ='ID', value='tax', line=4, column=8)
1414 Token(typ='ASSIGN', value=':=', line=4, column=12) 1422 Token(typ='ASSIGN', value=':=', line=4, column=12)
1415 Token(typ='ID', value='price', line=4, column=15) 1423 Token(typ='ID', value='price', line=4, column=15)
1416 Token(typ='OP', value='*', line=4, column=21) 1424 Token(typ='OP', value='*', line=4, column=21)
1417 Token(typ='NUMBER', value='0.05', line=4, column=23) 1425 Token(typ='NUMBER', value='0.05', line=4, column=23)
1418 Token(typ='END', value=';', line=4, column=27) 1426 Token(typ='END', value=';', line=4, column=27)
1419 Token(typ='ENDIF', value='ENDIF', line=5, column=4) 1427 Token(typ='ENDIF', value='ENDIF', line=5, column=4)
1420 Token(typ='END', value=';', line=5, column=9) 1428 Token(typ='END', value=';', line=5, column=9)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+