如何从第二次出现的字符中拆分字符串
str = "20050451100_9253629709-2-2" I need the output ["20110504151100_9253629709-2","2"]
解决方法
您可以使用正则表达式匹配:
str = "20050451100_9253629709-2-2" m = str.match /(.+)-(\d+)/ [m[1],m[2]] # => ["20050451100_9253629709-2","2"]
正则表达式匹配“任何”,后跟破折号,后跟数字.