I am currently writing an application in JavaScript where I map input to regular expressions, but I also need to find a way to match strings to parts of regular expressions.
For instance:
var invalid = "x", potentially = "g", valid = "ggg", gReg = /^ggg$/; gReg.test(invalid); //returns false (correct) gReg.test(valid); //returns true (correct)
Now I need to find a way to somehow determine that the value of the variable potentially does not exactly match the expression /^ggg$/ , but with a lot of input, this is potentially possible!
So, for example, in this case the variable potentially has the value g , but if two more g are added to it, it will correspond to the regular expression /^ggg$/
But in the case of invalid it can never match the expression /^ggg$/ , no matter how many characters you add to it.
So, how can I determine if a string or not has the potential to match a particular regular expression?
source share