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
Post a Comment