@@ -602,40 +602,14 @@ functions are simplified versions of the full featured methods for compiled
602
602
regular expressions. Most non-trivial applications always use the compiled
603
603
form.
604
604
605
+
606
+ Flags
607
+ ^^^^^
608
+
605
609
.. versionchanged :: 3.6
606
610
Flag constants are now instances of :class: `RegexFlag `, which is a subclass of
607
611
:class: `enum.IntFlag `.
608
612
609
- .. function :: compile(pattern, flags=0)
610
-
611
- Compile a regular expression pattern into a :ref: `regular expression object
612
- <re-objects>`, which can be used for matching using its
613
- :func: `~Pattern.match `, :func: `~Pattern.search ` and other methods, described
614
- below.
615
-
616
- The expression's behaviour can be modified by specifying a *flags * value.
617
- Values can be any of the following variables, combined using bitwise OR (the
618
- ``| `` operator).
619
-
620
- The sequence ::
621
-
622
- prog = re.compile(pattern)
623
- result = prog.match(string)
624
-
625
- is equivalent to ::
626
-
627
- result = re.match(pattern, string)
628
-
629
- but using :func: `re.compile ` and saving the resulting regular expression
630
- object for reuse is more efficient when the expression will be used several
631
- times in a single program.
632
-
633
- .. note ::
634
-
635
- The compiled versions of the most recent patterns passed to
636
- :func: `re.compile ` and the module-level matching functions are cached, so
637
- programs that use only a few regular expressions at a time needn't worry
638
- about compiling regular expressions.
639
613
640
614
641
615
.. data :: A
@@ -744,6 +718,41 @@ form.
744
718
Corresponds to the inline flag ``(?x) ``.
745
719
746
720
721
+ Functions
722
+ ^^^^^^^^^
723
+
724
+ .. function :: compile(pattern, flags=0)
725
+
726
+ Compile a regular expression pattern into a :ref: `regular expression object
727
+ <re-objects>`, which can be used for matching using its
728
+ :func: `~Pattern.match `, :func: `~Pattern.search ` and other methods, described
729
+ below.
730
+
731
+ The expression's behaviour can be modified by specifying a *flags * value.
732
+ Values can be any of the following variables, combined using bitwise OR (the
733
+ ``| `` operator).
734
+
735
+ The sequence ::
736
+
737
+ prog = re.compile(pattern)
738
+ result = prog.match(string)
739
+
740
+ is equivalent to ::
741
+
742
+ result = re.match(pattern, string)
743
+
744
+ but using :func: `re.compile ` and saving the resulting regular expression
745
+ object for reuse is more efficient when the expression will be used several
746
+ times in a single program.
747
+
748
+ .. note ::
749
+
750
+ The compiled versions of the most recent patterns passed to
751
+ :func: `re.compile ` and the module-level matching functions are cached, so
752
+ programs that use only a few regular expressions at a time needn't worry
753
+ about compiling regular expressions.
754
+
755
+
747
756
.. function :: search(pattern, string, flags=0)
748
757
749
758
Scan through *string * looking for the first location where the regular expression
@@ -975,6 +984,9 @@ form.
975
984
Clear the regular expression cache.
976
985
977
986
987
+ Exceptions
988
+ ^^^^^^^^^^
989
+
978
990
.. exception :: error(msg, pattern=None, pos=None)
979
991
980
992
Exception raised when a string passed to one of the functions here is not a
0 commit comments