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