The findall method in python re library has the following signature:
re.findall(pattern, string, flags=0)
Surprisingly the description below it on the python docs doesn't explain what is the meaning of the third
a parameter called flag
(
and scroll down to where the hits in the sidebar concentrate.
You'll find them f.e. documented in the inline flags for patterns:
(?aiLmsux)
(One or more letters from the set 'a', 'i', 'L', 'm', 's', 'u', 'x'.) The group matches the empty string; the letters set the corresponding flags: re.A (ASCII-only matching), re.I (ignore case), re.L (locale dependent), re.M (multi-line), re.S (dot matches all), re.U (Unicode matching), and re.X (verbose), for the entire regular expression. (The flags are described in Module Contents.) This is useful if you wish to include the flags as part of the regular expression, instead of passing a flag argument to the re.compile() function. Flags should be used first in the expression string.
which relegates you to
Module Contents
The module defines several functions, constants, and an exception. Some of the functions are simplified versions of the full featured methods for compiled regular expressions. Most non-trivial applications always use the compiled form.Changed in version 3.6: Flag constants are now instances of RegexFlag, which is a subclass of enum.IntFlag.
re.compile(pattern, flags=0)
Compile a regular expression pattern into a regular expression object, which can be used for matching using its match(), search() and other methods, described below.
which includes
The expression’s behaviour can be modified by specifying a flags value. Values can be any of the following variables, combined using bitwise OR (the | operator).
followed by all the flags there are...
CodePudding user response:
findall() module is used to search for “all” occurrences that match a given pattern. You need to have a pattern.. I think it will be good if you can provide a simple code so to see if I or someone else can help.
Pattern will be tested in the string to find all matches..
Flag is an optional parameter to a regex that modifies its behavior of searching. It only changes the default searching behaviour.