全部博文(108)
分类: Python/Ruby
2014-04-10 11:48:32
(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. (?PSimilar 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):
(?(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 '
New in version 2.4.
##如果找到指定的id或者name那么用yes-pattern匹配否则用no-pattern匹配。no-pattern是可选项。可忽略。
如 (<)?(\w+@\w+(?:\.\w+)+)?(l)>) 只会匹配