I need some analog of Python method of Regexp object - search. It has three arguments: text, start position and end position and returns Match object that has start and end fields.
I've got a function, that returns Match object, but I have no Idea how to implement endIndex in this function. I'm worring about performance and very reluctant to use substring method. Is there a feature that can be used in my case within Javascript ? Another question is there a library that provides the API similar to Python re module ?
function search(str, startIndex, endIndex) {
var re = new RegExp(this.matcher.source, 'g' + (this.matcher.ignoreCase ? 'i' : '') + (this.matcher.multiLine ? 'm' : ''));
re.lastIndex = startIndex || 0;
var value = re.exec(str);
if (!value)
return null;
var start = re.lastIndex - value[0].length;
var end = re.lastIndex;
return new Match(start, end);
}
substringand see how it performs, just put this at the start of your function:str = str.substring(startIndex, endIndex);then do the rest (well maybe validatestarIndexandendIndexfirst)