[Python]Regular Expression Syntax

ElementMeaning
.Matches any character except /n(if DOTALL, also matches /n)
^Matches start of string(if MULTILINE, also matches after /n)
$Matches end of string(if MULTILINE, also matches before /n)
*Matches zero or more cases of the previous RE; greedy(match as many as possible)
+Matches one or more cases of the previous RE; greedy(match as many as possible)
?Matches zero or one case of the previous RE; greedy(match one if possible)
*?, +?, ??Nongreedy versions of *, + and ?(match as few as possible)
{m,n}Matches m to n cases of the previous RE(greedy)
{m,n}?Matches m to n cases of the previous RE(nongreedy)
[...]Matches any one of a set of characters contained within the brackets
|Matches either preceding expression or following expression
(...)Matches the RE within the parentheses and indicates a group
(?iLmsux)  Alternate way to set optional flags; no errect on match
(?:...) Like (...), but does not indicate a group 
(?P<id>...) Like (...), but the group also gets the name id 
(?P=id) Matches whatever was previously matched by group named id 
(?#...) Content of parentheses is just a comment; no effect on match 
(?=...) Lookahead assertion: matches if RE ... matches what comes next, but does not consume any part of the string 
(?!...) Negative lookahead assertion: matches if RE ... does not match waht comes next, and does not consume any part of the string 
(?<=...) Lookbehind assertion: matches if there is a match ending at the current position for RE ... (... must match a fixed length) 
(?<!...) Negative lookbehind assertion: matches if there is no match ending at the current position for RE ... (... must match a fixed length)
/number Matches whatever was previously matched by group numbered number(groups are automatically numbered from 1 to 99)
/A

Matches an empty string, but only at the start of the whole string

/b Matches an empty string but only at the start or end of a word(a maximal sequence of alphanumeric characters; see also /w)
/B Matches an empty string, but not at the start or end of a word 
/d Matches one digit, like the set [0-9] 
/D Matches one non digit, like the set [^0-9]
/s Matches a whitespace character, like the set [/t/n/r/f/v] 
/S Matches a non whitespace character, like the set [^/t/n/r/f/v] 
/w Matches one alphanumeric character; unless LOCALE or UNICODE is set, /w is like [a-zA-Z0-9_] 
/W Matches one non alphanumeric character, the reverse of /w
/Z Matches an empty string, but only at the end of the whole string 
// Matches one backslash character 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值