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

Ash Berlin ash_js at firemirror.com
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]
> - s.search(/[delimiters]/) is useless, because it always starts
> searching at index 0 - you would have to cut/change s after each find

s.search 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.

-ash



More information about the es-discuss mailing list