findall-string
v1.0.0
Published
Find all occurrences of a string in another string.
Downloads
5
Readme
find all occurrences of a string in another.
use it like this:
var findall = require('findall-string')
findall('house', 'a house is a house is a house') // [2, 13, 24]
this is the full code of this package, for your delight:
module.exports = function findall (needle, haystack) {
var prev = 0
var indexes = []
while (true) {
var r = haystack.search(needle)
if (r === -1) {
return indexes
}
indexes.push(r + prev)
prev = r + prev + 1
haystack = haystack.slice(r + 1)
}
}
no regex.