Confused. Are you saying you’d like to call a function once for a string like this:
“I play games because playing games is fun, but replaying played games is boring.”
And have it (in a single call) tell you the positions of:
- play 3
- playing 22
- played …
but to ignore replaying?
You can make your own function to do this, but string.find() needs to be called repeatedly to get that kind of info.
Something like this:
function string.multifind( str, pattern ) local found = {} local i = 1 while( i != nil ) do i = str:find( pattern, i ) if( i ~= nil ) then found[#found+1] = i i = i + 1 end end if( #found \< 1) then return nil end return found end
returns nil or table of first indexes for each ‘find’
Note: This DOES NOT handle the rule for NOT matching play embedded in a word. You’ll need to make this a bit more elaborate to do that.