Finding parenthesis via regular expression

后端 未结 3 1310
情话喂你
情话喂你 2021-01-26 04:51

I am not great with regular expressions. I am looking to find if a string contains \"( ),[ ], { }\". Note, I am not looking for the contents in the actual ( ), just to see if

3条回答
  •  萌比男神i
    2021-01-26 05:17

    If you want to check for matching parens / brackets / braces, this will work:

    /\(.*\)|\{.*\}|\[.*\]/
    

    see here for more.

    And this returns the matching portions of your string:

    >> "alkd(jfla)kjd{adlkfj}alkjfd".scan(/\(.*\)|\{.*\}|\[.*\]/)
    => ["(jfla)", "{adlkfj}"]
    

提交回复
热议问题