alfonso
alfonso

Reputation: 105

How to remove number inside the brackets with R?

I have :

String=“text(2019),text1(2015),text2(Napoli 2018) . Text5(Milan 2019) 

Desidered output:

text,text1,text2(Napoli 2018). Text5(Milan 2019)

Then, I want delete only (2019) , (2015) and not (Napoli 2018 ) and (Milan 2019)

Thanks !

Upvotes: 0

Views: 291

Answers (1)

Pushpesh Kumar Rajwanshi
Pushpesh Kumar Rajwanshi

Reputation: 18357

Replace \(\d+\) with empty string.

data <- c("text(2019),text1(2015),text2(Napoli 2018) . Text5(Milan 2019)")
gsub("\\(\\d+\\)", "", data)

Prints,

[1] "text,text1,text2(Napoli 2018) . Text5(Milan 2019)"

Online R demo

Upvotes: 2

Related Questions