Question: I have some sequences in a string denoted by "@number" (/@\d/)
I want to remove any redundant sequences, where @2 is followed by @2, 
I only want to remove them if another identical @number sequence is found directly after somewhere in the text, so for `@2lorem@2ipsum` the 2nd @2 is removed, but for `@2lorem@1ipsum@2dolor` nothing is removed because @1 is between the two @2 sequences.

```
"@2randomtext@2randomtext@2randomtext@1bla@2bla2@2bla2"

```

becomes:

```
"@2randomtextrandomtextrandomtext@1bla@2bla2bla2

```

Answer: 
```
"@2randomtext@2randomtext@2randomtext@1bla@2bla2@2bla2".gsub /(?<=(@\d))([^@]*)\1/,'\2'
=> "@2randomtextrandomtextrandomtext@1bla@2bla2bla2"

```
```
my_string = "@2randomtext@2randomtext@2randomtext@1bla@2bla2@2bla2"

prev_sequence = String.new
penultimate_index = my_string.length - 2

for i in 0..penultimate_index
  if my_string[i] == '@'
    new_sequence = "@#{my_string[i+1]}"
    if new_sequence == prev_sequence
      my_string.slice!( i, 2 )
    else 
      prev_sequence = new_sequence
    end
  end
end

puts my_string

```