使用Regex作为分隔符来分割字符串

Har*_*lly 2 ruby regex split

我想将以下字符串拆分为两个子字符串."somestring(otherstring)"

我带来了以下正则表达式分裂

"somestring(otherstring)".split(/(.+)\((.+)\)/)
Run Code Online (Sandbox Code Playgroud)

但这排除了以下字符串,其中没有大括号中的子字符串.."somestring"

如何更改正则表达式,以便即使没有模式"(otherstring)"的子字符串,它仍然会生成第一个子字符串作为输出.

非常感谢!

kur*_*umi 8

>> "somestring(otherstring)".split(/[()]/)
=> ["somestring", "otherstring"]
>> "somestring".split(/[()]/)
=> ["somestring"]
Run Code Online (Sandbox Code Playgroud)