How to capture multiple repeated groups?

前端 未结 7 1633
傲寒
傲寒 2020-11-22 10:59

I need to capture multiple groups of the same pattern. Suppose, I have a following string:

HELLO,THERE,WORLD

And I\'ve written a following

7条回答
  •  时光说笑
    2020-11-22 11:24

    I know that my answer came late but it happens to me today and I solved it with the following approach:

    ^(([A-Z]+),)+([A-Z]+)$
    

    So the first group (([A-Z]+),)+ will match all the repeated patterns except the final one ([A-Z]+) that will match the final one. and this will be dynamic no matter how many repeated groups in the string.

提交回复
热议问题