-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
Case 1: message ends with the matched word
message = "I love this new status update"
=> "I love this new status update"
matched_string = message.match(/status update/)[0]
=> "status update"
message.rindex(matched_string)
=> 16
message.rindex("status update")
=> 16
Case 2: message does not end with the matched word
message = "I love this new status update..."
=> "I love this new status update..."
matched_string = message.match(/status update/)[0]
=> "status update"
message.rindex(matched_string)
=> 19
message.rindex("status update")
=> 16
I am not sure why this would happen, matched_string is just a string, the value is the same "status update", how does it pickup the ... from the end of the message.
I tried in MRI ruby 1.9.3-p545 and 2.1.1, the issue does not occur.
Also I find if I do message.rindex(matched_string.tr("", ""))), the result will be 16.
But
matched_string.to_java_bytes
=> byte[115, 116, 97, 116, 117, 115, 32, 117, 112, 100, 97, 116, 101]@543c5bbd
"status update".to_java_bytes
=> byte[115, 116, 97, 116, 117, 115, 32, 117, 112, 100, 97, 116, 101]@46ab007f
And
matched_string.bytesize
=> 13
"status update".bytesize
=> 13
I don't see any special characters in the matched_string.