开发者

Simple regular expression

I'm new to regular expressions and tried to use the following concept:

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

in this way:

import re

print re.match("(?(\w),+)", "a,,,,,").groups()

Got the following error :

error: 'bad character in group name'. 

Unfortunately I couldn't figure out what's wrong about this expression?

开发者_开发问答

Thanks in advance!


You didn't write a valid id or name.

I found the definition:

(?(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 '<user@host.com>' as well as 'user@host.com', but not with '<user@host.com'.

New in version 2.4.

In your case, you haven't provided the id/name of a group to search for. Are you sure that this is the feature you want?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜