I need to match a string that has a valid length prefix for this string.
For example, {3}abc will match because the abc part is 3 . {3}abcd will fail because abcd no longer than 3 .
I would use ^\{(\d+)\}.{\1}$ (grab the number N inside the braces, then any character N times), but it turns out that the value in the repetition construct should be a number (or at least , accept the back link).
For example, in JavaScript, this returns true:
/^\{(\d+)\}.{3}$/.test("{3}abc")
So far, this returns false:
/^\{(\d+)\}.{\1}$/.test("{3}abc")
Is it possible to do this in one regular expression, or do I need to resort to splitting it into two stages, for example:
/^\{(\d+)\}/.test("{3}abc") && RegExp("^\\{" + RegExp.$1 + "\\}.{" + RegExp.$1 + "}$").test("{3}abc")
source share