Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482238
  • 博文数量: 108
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 1134
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-29 19:43
文章分类

全部博文(108)

文章存档

2016年(10)

2015年(9)

2014年(73)

2013年(16)

我的朋友

分类: Python/Ruby

2014-04-10 11:48:32

(?iLmsux)

(One or more letters from the set 'i''L''m''s''u''x'.) The group matches the empty string; the letters set the corresponding flags:  (ignore case),  (locale dependent),  (multi-line),  (dot matches all), (Unicode dependent), and  (verbose), for the entire regular expression. (The flags are described in .) This is useful if you wish to include the flags as part of the regular expression, instead of passing a flag argument to the  function.

Note that the (?x) flag changes how the expression is parsed. It should be used first in the expression string, or after one or more whitespace characters. If there are non-whitespace characters before the flag, the results are undefined.

(?:...) A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern. (?P...)

Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named.

Named groups can be referenced in three contexts. If the pattern is (?P['"]).*?(?P=quote) (i.e. matching a string quoted with either single or double quotes):


(?#...) A comment; the contents of the parentheses are simply ignored. (?=...) Matches if ... matches next, but doesn’t consume any of the string. This is called a lookahead assertion. For example, Isaac (?=Asimov) will match 'Isaac ' only if it’s followed by 'Asimov'. (?!...) Matches if ... doesn’t match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match 'Isaac ' only if it’s not followed by 'Asimov'. (?<=...)




[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> m=re.search('(?<=check)string','checkstring')
>>> m.group(0)
'string'
>>> m=re.search('(?<=-)\w+','spam-egg')
>>> m.group(0)
'egg'
>>> 



(?(id/name)yes-pattern|no-pattern)

Will try to match with yes-pattern if the group with given id or name exists, and with no-pattern if it doesn’t. no-pattern is optional and can be omitted. For example, (<)?(\w+@\w+(?:\.\w+)+)(?(1)>) is a poor email matching pattern, which will match with '' as well as 'user@host.com', but not with '.

New in version 2.4.

##如果找到指定的id或者name那么用yes-pattern匹配否则用no-pattern匹配。no-pattern是可选项。可忽略。
如 (<)?(\w+@\w+(?:\.\w+)+)?(l)>)  只会匹配 ,user@host.com但不匹配


阅读(740) | 评论(0) | 转发(0) |
0

上一篇:some link

下一篇:Python re模块的一些方法

给主人留下些什么吧!~~