From: bwv549 Date: 2007-07-24T05:54:59+09:00 Subject: finding positions in a string I have a long string and I need to know the starting position of all substrings matching a particular sequence. Most importantly, it needs to be fast. Secondly, it would be nice if it was somewhat concise. Here's the method: def substring_positions(substring, string) ## fast, concise method?? end my_substring = 'this' my_string = 'this string this is a string this is it' substring_positions(my_substring, my_string) # -> should return [0, 12, 29] This seems trivial to do, but looking at StringScanner, String#match, and String#scan, nothing simple comes to mind. There must be a one- liner somewhere for this kind of thing. I checked through facets and didn't see anything... Thanks