Here's the command :
grep '\(2\)[[:digit:]]\{\1\}' numbers
What I want is to match exactly 2 digits after the digit '2', 3 digits if I change the digit '2' to '3' in my expression, 4 digits if …
I'm using back-referencing here but when I execute this command I have the following output :
grep: invalid content of \{\}
How could one change my expression ?
first solution :
As serge answered :
2[[:digit:]]\{1\}\|3[[:digit:]]\{2\}\|4[[:digit:]]\{3\}\|5[[:digit:]]\{4\}
That could actually work, but let's suppose I have \(34\)
as the first sub-expression, I wish I could back-referencing that number so I don't have to implement the 34 cases (or more).
Best Answer
Back-references are not allowed here. You have to write the expression that will describe all possible cases, e.g.: