加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Set Regular Expression Options (设置正则表达式选项)

发布时间:2020-12-14 01:46:49 所属栏目:百科 来源:网络整理
导读:需求: free-spacing,case insensitive,dot matches lines breaks,and "^ and $ match at line breaks" 实现 a. Python: import re reobj = re.compile("regex pattern", re.VERBOSE | re.IGNORECASE | re.DOTALL | re.MULTILINE) 说明: Free-spacing: re.V

需求:

free-spacing,case insensitive,dot matches lines breaks,and "^ and $ match at line breaks"


实现

a. Python:

import re

reobj = re.compile("regex pattern",

re.VERBOSE | re.IGNORECASE |

re.DOTALL | re.MULTILINE)


说明:

Free-spacing: re.VERBOSE or re.X

Case insentitive: re.IGNORECASE or re.I

DOt matches line breaks: re.DOTALL or re.S

^ and $ match at line breaks: re.MULTILINE or re.M


补充:

Extra options to change the meaning of word bounaries and the shorthand character classes w d s,as well as their negated counterparts

By default,these tokens deal only with ASCII letters,digits,and whitespace.


re.LOCALE or re.L option makes these tokens dependent on the current locale.

re.UNICODE or re.U makes these tokens dependent on the Unicode standard


b. Tcl

set result [regexp -nocase -lineanchor -expanded {abc} $subject]


说明:

Free-spacing: -expanded

Case insentitive: -nocase

DOt matches line breaks: do not set-linestop

^ and $ match at line breaks: -lineanchor

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读