我有一个字符串,如下所示,
./component/unit
并且需要拆分以获得作为 component/unit
的结果,我将使用它作为插入哈希的键。
我尝试使用 .split(/.\//).last
但它给出的结果是 unit
只是没有得到 component/unit
.
最佳答案
我想,这应该可以帮到你:
string = './component/unit'
string.split('./')
#=> ["", "component/unit"]
string.split('./').last
#=> "component/unit"
关于ruby - 如何拆分包含多个正斜杠的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41146182/