We\'ve got such regexp:
var regexp = /^one (two)+ three/;
So only string like \"one two three\" or \"one two three four\
Basing on @Andacious answer, I've made my own, a little more advanced and it seems to work.
I've made method that modifies regex making it accepting promising answers.
It replaces any literal char with "(?:OLD_LETTER|$)" so k becomes (?:k|$) looking for matching letter or end of input.
It also looks for parts not to replace like {1,2} and leave them as they are.
I'm sure it's not complete, but its very easy to add new rules of checking and main trick with any_sign or end of input seems to work in any case as end of string match and dont continue so basically we need to make such modification to main regex, that any literal char or group of chars will have alternative |$ and every syntax (that sometimes seems to have literal chars too) can't be destroyed.
RegExp.prototype.promising = function(){
var source = this.source;
var regexps = {
replaceCandidates : /(\{[\d,]\})|(\[[\w-]+\])|((?:\\\w))|([\w\s-])/g, //parts of regexp that may be replaced
dontReplace : /\{[\d,]\}/g, //dont replace those
}
source = source.replace(regexps.replaceCandidates, function(n){
if ( regexps.dontReplace.test(n) ) return n;
return "(?:" + n + "|$)";
});
source = source.replace(/\s/g, function(s){
return "(?:" + s + "|$)";
});
return new RegExp(source);
}
Test on jsFiddle