what's the regular expression to find two sets of parenthesis in a row using perl?

前端 未结 3 1226
我在风中等你
我在风中等你 2021-01-23 09:26

I have rows with different sets of parenthesis. For example

     (sdfsfs) (sfdsfd) 
     (sdfsfs) (sfdsfd) (sfdsfd) 
     (sdfsfs) (sfdsfd) (sfdsfd) (sfdsfd)
            


        
3条回答
  •  灰色年华
    2021-01-23 09:41

    You can use this regex to match a line with exactly 2 parentheses sets:

    m/^(\([^)]*\)\s*){2}$/
    

    OR:

    m/^\([^)]*\)\s*\([^)]*\)$/
    

    RegEx Demo

    [^)]* will match any character but ) and is more efficient than .*? or .*.

提交回复
热议问题