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

相关文章

jquery.validate使用攻略(表单校验) 目录 jquery.validate...
/\s+/g和/\s/g的区别 正则表达式/\s+/g...
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母...
this.optional(element)的用法 this.optional(element)是jqu...
jQuery.validate 表单动态验证 实际上jQuery.validate提供了...
自定义验证之这能输入数字(包括小数 负数 ) <script ...