Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字符串的python正则表达式_Python_Regex - Fatal编程技术网

字符串的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

我有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 not one of the allowed values `\(\[(?:\w+, )*\w+\]\)`
修正:

  • 值之后添加空格
  • \]\)
    结尾,而不是
    \)\]
  • 在括号内,需要允许多个
    \w
    ,因此它应该是
    \w+
  • 之后需要一个空格
  • 需要在
    \w+,
    周围建立一个组,以使用
    *
    量词匹配多个逗号分隔的单词
  • 然后必须匹配最后一个单词,后面没有逗号

  • 您可以使用以下选项:

    \w+ is not one of the allowed values `\(\[[\w,\s]+\]\)`
    

    不对。有多模糊?您希望实现什么。您想做什么?regexp在
    值之后没有空格,在
    ([])内的逗号之后也没有空格。它还只允许
    \w
    内的
    ([])
    和多个
    ,括号内的最后一个单词后面需要一个逗号。
    \)\]
    应该是
    \]\)
    。这么多像这样的简单错误。这将在最后匹配
    ([,word,])
    。但也许这已经足够好了。