ruby-on-rails – 在最后一个字符出现后拆分字符串
发布时间:2020-12-17 02:40:00 所属栏目:百科 来源:网络整理
导读:我有以下字符串: this sentence: should be: splited after last colon: sentence 所以我想在最后一个冒号之后拆分上面的句子:出现如下: ["this sentence: should be: splited after last colon:","sentence"] 任何帮助? 解决方法 尝试简单的代码: s =
我有以下字符串:
this sentence: should be: splited after last colon: sentence 所以我想在最后一个冒号之后拆分上面的句子:出现如下: ["this sentence: should be: splited after last colon:","sentence"] 任何帮助? 解决方法
尝试简单的代码:
s = 'this sentence: should be: splited after last colon: sentence' s =~ /(.*):(.*)?/ [ $1 << ':',$2 ] # => ["this sentence: should be: splited after last colon:"," sentence"] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |