Set Regular Expression Options (设置正则表达式选项)
2014-05-12 09:10
567 查看
需求:
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
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
相关文章推荐
- 简单的正则表达式匹配 Regular Expression Matching
- RegularExpressionValidator控件中常见正则表达式用法
- 多正则表达式匹配(Multiple Regular Expression Matching)
- RegularExpressionValidator控件中正则表达式用法
- PHP扩展之文本处理(二)——PCRE正则表达式语法7——内部选项设置
- .net2.0中的正则表达式的RegexOptions.Compiled选项
- [Leetcode] Regular expression matching 正则表达式匹配
- HTML RegularExpressionValidator 正则表达式
- 用于RegularExpressionValidator的正则表达式
- RegularExpressionValidator控件中常见正则表达式用法
- 简单的正则表达式http://www.cainiao8.com/web/js_note/js_regular_expression.html
- 【正则表达式判断】Regular Expression Matching
- leetcode 10 Regular Expression Matching(简单正则表达式匹配)
- Regularexpressionvalidator控件常用正则表达式
- 正则表达式匹配-leetcode Regular Expression Matching
- RegularExpressionValidator控件中常见正则表达式用法
- Regularexpressionvalidator控件常用正则表达式
- [leetcode]Regular Expression Matching(正则表达式的匹配)
- 带正则表达式编辑器的RegularExpressionValidator[ASP.NET2.0 Server Control]
- RegularExpressionValidator控件中常见正则表达式用法