I have a case where I'm using regex to check a string for matches, after a start index and before an end one.
To set the start point, it is possible to create a new Regexp() and set it's index before running exec().
I can not find a way, though, to limit the depth of its search. One "obvious" solution might be to use substring() to get a string that can't be searched passed a point, but it would have a massive negative impact on performance. Any solution to setting a limit on regex search depth that includes substring() will not do, and is IMO embarrassingly inefficient, so please do not post them.
The three ways I can imagine fixing this are:
if there is some way to set a limit, such as
myRegex.exec(string, stopIndex)ormyString.length = temporaryFakeLimit; //do regex, reset length. Neither of these work or exist.if there was some way to check for a regex match at an index in a string ie
myRegex.testAt(myString, indexToCheck), I could iterate through the string myself, checking for matches.if there was a non-native implementation of regex, which is capable of doing either of the above.
So far I have not been able to find a good solution.
How can I check if a Regex has a match in a string before some index, without it searching the entire string?
Edit (Not by OP)
To add further:
If it doesn't find a match, and I'm only looking 100 chars deep on a 100000 char text, that's an issue.
How can we search a portion of a given string using RegEx. This portion of string should be determined by parameters indicating a start index and an end index.
Example of Parameters
var str = `Check enhancement bonus fear effect fly initiative check panicked points of damage rounding stunned touch attack unarmed strike. Aquatic subtype attack of opportunity catching on fire charm conjuration deafened evasion evil domain fast healing favored class fire domain gaseous form healing subschool incorporeal melee weapon multiplying skill points stunned summoning subschool take 10 turn. Adjacent class concentrate on a spell energy drained infection intelligence invisible law domain mundane nonlethal damage small.`;
var rgx = /\d\d/;
var start = 300;
var end = 500;
The result should be:
10