0

at the beginning, yes - simillar questions are present here, however the solution doesn't work as it should - at least for me.

I'd like to remove all characters, letters and numbers with any combination before first semicolon, and also remove it too.

So we have some strings:

x <- "1;ABC;GEF2"
y <- "X;EER;3DR"

Let's do so gsub() with . and * which means any symbol with occurance 0 or more:

gsub(".*;", "", x)
gsub(".*;", "", y)

And as a result i get:

[1] "GEF2"
[1] "3DR"

But I'd like to have:

[1] "ABC;GEF2"
[1] "EER;3DR"

Why did it 'catch' second occurence of semicolon instead of first?

Adamm
  • 2,150
  • 22
  • 30

1 Answers1

2

You could use

gsub("[^;]*;(.*)", "\\1", x)
# [1] "ABC;GEF2"
Jan
  • 42,290
  • 8
  • 54
  • 79