0

I have a string pattern of the following form:-

k <- "KK <yvsrss k p p > kfsqs > jijiji >> <yvsrss hjh hjhjh>"

Now, from this I want everything between the <yvsrss and > removed, including the yvsrss. So when I use the following code:-

gsub("<yvsrss.*>", "", k)

it gives the following output

[1] "KK "

I.E. it deletes everything between the first <yvsrss and last >. Whereas I want the following output:-

[1] "KK kfsqs > jijiji >>"

So, everything between the <yvsrss and the first > should be deleted. How can I do this??

Thanks in advance.

Shawn Brar
  • 1,084
  • 2
  • 13
  • 1
    The easiest fix is probably `gsub("]*>", "", k)`. Rather than `.*` just make sure to only match non-> characters or use a non-greedy match: `gsub("", "", k)` – MrFlick Aug 05 '21 at 07:03

0 Answers0