首页 / 正则 / Python正则表达式是否允许嵌入选项?
Python正则表达式是否允许嵌入选项?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python正则表达式是否允许嵌入选项?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1192字,纯文字阅读大概需要2分钟。
内容图文
![Python正则表达式是否允许嵌入选项?](/upload/InfoBanner/zyjiaocheng/812/496631e53d1c41e89a4bec027ea5f0b7.jpg)
特别是,我想知道我是否可以在模式字符串中指定一个嵌入式选项来启用多行模式.也就是说,通常使用Python正则表达式启用多行模式,如下所示:
pattern = re.compile(r'foo', re.MULTILINE)
我想通过在模式字符串中指定多线匹配来获得多线匹配,而不是使用re.MULTILINE选项.您可以使用嵌入式(?m)表达式在Java中执行此操作.例如.,
pattern = re.compile(r'(?m)foo')
这在Python中是否可行,或者我是否需要使用re.M选项?一般来说,Python中的嵌入式模式选项是否有很好的参考?
解决方法:
是.
从docs:
(?iLmsux)
(One or more letters from the set ‘i’,
‘L’, ‘m’, ‘s’, ‘u’, ‘x’.)The group
matches the empty string; the letters
set the corresponding flags: 07001
(ignore case), 07002 (locale
dependent), 07003 (multi-line), 07004
(dot matches all), 07005 (Unicode
dependent), and 07006 (verbose), for
the entire regular expression. (The
flags are described in 07007.)This is useful if you wish
to include the flags as part of the
regular expression, instead of passing
a flag argument to thecompile()
function.Note that the
(?x)
flag changes how
the expression is parsed. It should be
used first in the expression string,
or after one or more whitespace
characters. If there are
non-whitespace characters before the
flag, the results are undefined.
内容总结
以上是互联网集市为您收集整理的Python正则表达式是否允许嵌入选项?全部内容,希望文章能够帮你解决Python正则表达式是否允许嵌入选项?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。