String.indexOf/lastIndexOf/search should have optional arguments fromIndex/toIndex

Ash Berlin ash_js at
Tue Dec 29 05:19:12 PST 2009

On 29 Dec 2009, at 12:36, Karsten Düsterloh wrote:

> Let d be a set of delimiters and s be a long string including several of
> these delimiters in arbitrary order and count. Now try to process each
> block of text between two such delimiters in dependance upon the
> surrounding delimiters:
> [snip]
> -[delimiters]/) is useless, because it always starts
> searching at index 0 - you would have to cut/change s after each find might be useless, but

re = /[delimiters]/g;
while ( ( m = re(s) ) != null ) {

works. and the fromIndex can be controlled by adjusting re.lastIndex (which is a badly named parameter - its behaviour is to control where the next match should start -- I think) This is to say nothing about the usefulness of toIndex arguments.


More information about the es-discuss mailing list