pasternak
pasternak

Reputation: 403

Regex in R using grep

I have a string and I want to check if it is ending with "(n)" where n is any natural number and quotes are not included. an example of this is

"320_50iz_toSTORE(29)"

I am trying grep

> grep("$([:digit:])",E)
integer(0)

Further, I want to replace the match(if found) with empty string. so "320_50iz_toSTORE(29)" should go to "320_50iz_toSTORE"

Upvotes: 0

Views: 54

Answers (1)

akrun
akrun

Reputation: 886948

Here is one option

sub("[(][0-9]+[)]$", "", "320_50iz_toSTORE(29)")
#[1] "320_50iz_toSTORE"

Upvotes: 2

Related Questions