Skip to main content
deleted 13 characters in body
Source Link
vdegenne
  • 1.8k
  • 3
  • 19
  • 20

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 ...you got it

I'm using backreferencingback-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 supposedlet's suppose I have : (34) has\(34\) as the first sub-expression, I wish I could back-referencing that number so I don't have to implement the 34 results for each casecases (or more).

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 ...you got it

I'm using backreferencing 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 work, but supposed I have : (34) has the first sub-expression, I wish I could back-referencing that number so I don't have to implement 34 results for each case (or more).

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).

added 41 characters in body
Source Link
vdegenne
  • 1.8k
  • 3
  • 19
  • 20

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 ...you got it

I'm using backreferencing 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 work, but it could be hundreds of digits to match dependingsupposed I have : (34) has the first digitsub-expression, I wish I could back-referencing that number so I don't wanthave to write everyimplement 34 results for each case. Any other suggestions ?(or more).

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 ...you got it

I'm using backreferencing 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 work, but it could be hundreds of digits to match depending the first digit, I don't want to write every case. Any other suggestions ?

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 ...you got it

I'm using backreferencing 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 work, but supposed I have : (34) has the first sub-expression, I wish I could back-referencing that number so I don't have to implement 34 results for each case (or more).

added 258 characters in body
Source Link
vdegenne
  • 1.8k
  • 3
  • 19
  • 20

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 ...you got it

I'm using backreferencing 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 work, but it could be hundreds of digits to match depending the first digit, I don't want to write every case. Any other suggestions ?

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 ...you got it

I'm using backreferencing here but when I execute this command I have the following output :

grep: invalid content of \{\}

How could one change my expression ?

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 ...you got it

I'm using backreferencing 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 work, but it could be hundreds of digits to match depending the first digit, I don't want to write every case. Any other suggestions ?

Source Link
vdegenne
  • 1.8k
  • 3
  • 19
  • 20
Loading