ruby - Using Regex as delimeter to split a string -


i want split following strings 2 substrings. "somestring(otherstring)"

i came following regex split

"somestring(otherstring)".split(/(.+)\((.+)\)/) 

but excludes following strings, dont have substring in braces.. "somestring"

how can change regex that, if there not substring of pattern "(otherstring)", still generates first substring output.

thanks lot in advance!

>> "somestring(otherstring)".split(/[()]/) => ["somestring", "otherstring"] >> "somestring".split(/[()]/) => ["somestring"] 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -