@@ -665,40 +665,14 @@ functions are simplified versions of the full featured methods for compiled
665
665
regular expressions. Most non-trivial applications always use the compiled
666
666
form.
667
667
668
+
669
+ Flags
670
+ ^^^^^
671
+
668
672
.. versionchanged :: 3.6
669
673
Flag constants are now instances of :class: `RegexFlag `, which is a subclass of
670
674
:class: `enum.IntFlag `.
671
675
672
- .. function :: compile(pattern, flags=0)
673
-
674
- Compile a regular expression pattern into a :ref: `regular expression object
675
- <re-objects>`, which can be used for matching using its
676
- :func: `~Pattern.match `, :func: `~Pattern.search ` and other methods, described
677
- below.
678
-
679
- The expression's behaviour can be modified by specifying a *flags * value.
680
- Values can be any of the following variables, combined using bitwise OR (the
681
- ``| `` operator).
682
-
683
- The sequence ::
684
-
685
- prog = re.compile(pattern)
686
- result = prog.match(string)
687
-
688
- is equivalent to ::
689
-
690
- result = re.match(pattern, string)
691
-
692
- but using :func: `re.compile ` and saving the resulting regular expression
693
- object for reuse is more efficient when the expression will be used several
694
- times in a single program.
695
-
696
- .. note ::
697
-
698
- The compiled versions of the most recent patterns passed to
699
- :func: `re.compile ` and the module-level matching functions are cached, so
700
- programs that use only a few regular expressions at a time needn't worry
701
- about compiling regular expressions.
702
676
703
677
.. class :: RegexFlag
704
678
@@ -823,6 +797,41 @@ form.
823
797
Corresponds to the inline flag ``(?x) ``.
824
798
825
799
800
+ Functions
801
+ ^^^^^^^^^
802
+
803
+ .. function :: compile(pattern, flags=0)
804
+
805
+ Compile a regular expression pattern into a :ref: `regular expression object
806
+ <re-objects>`, which can be used for matching using its
807
+ :func: `~Pattern.match `, :func: `~Pattern.search ` and other methods, described
808
+ below.
809
+
810
+ The expression's behaviour can be modified by specifying a *flags * value.
811
+ Values can be any of the following variables, combined using bitwise OR (the
812
+ ``| `` operator).
813
+
814
+ The sequence ::
815
+
816
+ prog = re.compile(pattern)
817
+ result = prog.match(string)
818
+
819
+ is equivalent to ::
820
+
821
+ result = re.match(pattern, string)
822
+
823
+ but using :func: `re.compile ` and saving the resulting regular expression
824
+ object for reuse is more efficient when the expression will be used several
825
+ times in a single program.
826
+
827
+ .. note ::
828
+
829
+ The compiled versions of the most recent patterns passed to
830
+ :func: `re.compile ` and the module-level matching functions are cached, so
831
+ programs that use only a few regular expressions at a time needn't worry
832
+ about compiling regular expressions.
833
+
834
+
826
835
.. function :: search(pattern, string, flags=0)
827
836
828
837
Scan through *string * looking for the first location where the regular expression
@@ -1058,6 +1067,9 @@ form.
1058
1067
Clear the regular expression cache.
1059
1068
1060
1069
1070
+ Exceptions
1071
+ ^^^^^^^^^^
1072
+
1061
1073
.. exception :: error(msg, pattern=None, pos=None)
1062
1074
1063
1075
Exception raised when a string passed to one of the functions here is not a
0 commit comments