字符串的python正则表达式
我有python字符串字符串的python正则表达式,python,regex,Python,Regex,我有python字符串 wrong_data_type is not one of the allowed values `([one_two, two_three, three_four])` 我有一个regexp: \w+ is not one of the allowed values`\(\[\w,+\)\]` 但是,这是不对的?有什么帮助吗?regexp应该是 data = re.search(r'\(\[[\w,\s]+\]\)', string).group() \w+ is
wrong_data_type is not one of the allowed values `([one_two, two_three, three_four])`
我有一个regexp:
\w+ is not one of the allowed values`\(\[\w,+\)\]`
但是,这是不对的?有什么帮助吗?regexp应该是
data = re.search(r'\(\[[\w,\s]+\]\)', string).group()
\w+ is not one of the allowed values `\(\[(?:\w+, )*\w+\]\)`
修正:
值之后添加空格
\]\)
结尾,而不是\)\]
\w
,因此它应该是\w+
,
之后需要一个空格\w+,
周围建立一个组,以使用*
量词匹配多个逗号分隔的单词您可以使用以下选项:
\w+ is not one of the allowed values `\(\[[\w,\s]+\]\)`
不对。有多模糊?您希望实现什么。您想做什么?regexp在
值之后没有空格,在([])内的逗号之后也没有空格。它还只允许\w
内的([])
和多个,
,括号内的最后一个单词后面需要一个逗号。\)\]
应该是\]\)
。这么多像这样的简单错误。这将在最后匹配([,word,])
。但也许这已经足够好了。