Find first index of a string after index

This code might be helpful

var string = "www.google.com.sdg.jfh.sd",
  preString = "sdg",
  searchString = ".s",
  preIndex = string.indexOf(preString),
  searchIndex = preIndex + string.substring(preIndex).indexOf(searchString);

You can test it HERE


var str = "www.google.com.sdg.jfh.sd";
var search = "sdg";
var start_index = str.substring(str.indexOf(search) + search.length).indexOf(".s");

There's a second parameter which controls the starting position of search:

String.prototype.indexOf(arg, startPosition);

So you can do

str.indexOf('s', start_index);

Tags:

Javascript