difference between two regular expressions: [abc]+ and ([abc])+

前端 未结 5 1520
-上瘾入骨i
-上瘾入骨i 2020-12-06 18:44
In [29]: re.findall(\"([abc])+\",\"abc\")
Out[29]: [\'c\']

In [30]: re.findall(\"[abc]+\",\"abc\")
Out[30]: [\'abc\']

Confused by the grouped one.

5条回答
  •  既然无缘
    2020-12-06 19:28

    In the first example you have a repeated captured group which only capture the last iteration. Here c.

    ([abc])+
    

    Regular expression visualization

    Debuggex Demo

    In the second example you are matching a single character in the list one and unlimited times.

    [abc]+
    

    Regular expression visualization

    Debuggex Demo

提交回复
热议问题