Skip to content

replace parenthetical phrases in a string

3 messages · Adams, Jean, arun

#
Hi,

I guess there are some problems with spaces in this solution.

?y
[1] "My toast=bog? and eggs omit=32" "dogs have ears"??????????????? 
[3] "cats have tails? "???????????? 
?gsub(" *\\([^)]*\\) *", "", x)
#[1] "My toast=bogand eggsomit=32" "dogs have ears"???????????? 
#[3] "cats have tails"?? 


You could try this:
?gsub("(\\(.*\\))+?"," ",x)
#[1] "My toast=bog? and eggs omit=32" "dogs have ears"??????????????? 
#[3] "cats have tails? "???????? 
A.K.

----- Original Message -----
From: "Adams, Jean" <jvadams at usgs.gov>
To: r-help at r-project.org
Cc: 
Sent: Thursday, December 13, 2012 6:03 PM
Subject: Re: [R] replace parenthetical phrases in a string

My apologies.? I sent too soon!

I did a bit more digging, and found a solution on the R-help archives.

y <- gsub(" *\\([^)]*\\) *", "", x)

Jean
On Thu, Dec 13, 2012 at 4:53 PM, Adams, Jean <jvadams at usgs.gov> wrote:

            
??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.