说,我有一个以下字符串
string = "#Sachin is Indian cricketer. #Tendulkar is right hand batsman. #Sachin has been honoured with the Padma Vibhushan award "
我想要 o/p 作为
"#Sachin|0|7;#Tendulkar|29|10;#Sachinn|63|7;"
我试过以下
new_string = ""
string.scan(/#\S+/).each{|match| new_string+="#{match}|#{string.index(match)}|#{match.length};" }
这给了我
"#Sachin|0|7;#Tendulkar|29|10;#Sachin|0|7;"
那么我将如何获得每个子字符串的起始索引?