Python正则表达式,如何将有效字符添加到否定子节

时间:2013-02-17 08:03:16

标签: python regex

在以下Python正则表达式中:

pattern = re.compile(r"""
^                     # Match start of line.
([^\W\d]+)            # One or more word characters (including ê, etc.; but excluding 0-9) 
                      # as a returned group. Not \W and not \d.
$                     # Match end of line.
""", re.VERBOSE + re.UNICODE)

如何在[]?

中添加 - 字符(破折号)作为有效字符

1 个答案:

答案 0 :(得分:2)

您可以使用pipe合并两个正则表达式:

((?:[^\W\d]|-)+)