findall中的旗帜是什么意思

发布于 2025-01-25 11:15:47 字数 306 浏览 5 评论 0原文

Python Re库中的Findall方法具有以下签名:
re.findall(模式,字符串,标志= 0)
令人惊讶的是,在Python文档上的描述并未解释第三个
的含义是什么 一个称为flag的参数( https://docs.python。 org/3/library/re.html

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 (https://docs.python.org/3/library/re.html)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2025-02-01 11:15:47

只需在您的浏览器中搜索网站以查找“ flag”:

您会发现它们在内联标志中记录了FE的模式:

(?ailmsux)强>
(集合“ A”,“ I”,“ L','M','S”的一个或多个字母
'u','x'。)该组匹配空字符串;字母设置了
相应的标志: re.a (仅ASCII匹配), re.i (忽略案例),
re.l (位置依赖性), re.m (多行), re.s (点匹配全部),
re.u (unicode匹配)和 re.x (冗长),整个常规
表达。 (在模块内容中描述了标志。)这是
如果您想将标志包括在普通的一部分中,有用
表达式,而不是将标志参数传递给re.compile()
功能。标志应首先在表达式字符串中使用。


这使您降级


该模块定义了几个功能,常数和
一个例外。一些功能是简化的版本
完整的特色方法用于编译正则表达式。最多
非平凡的应用程序始终使用编译表格。

在版本3.6中更改:标志常数现在是Regexflag的实例,
这是枚举的子类。

re.compile(图案,flags = 0)
将正则表达模式编译到正则表达式对象中,该对象可用于使用其匹配(),search()和其他方法匹配,如下所述。

其中包括

可以通过指定标志值来修改表达式的行为。值可以是以下任何一个变量,使用位或(| operator)组合。

其次是所有旗帜

Simply search the site for "flag" in your browser:

flags searched in browser

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文