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

需求:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值