[R] How to remove square brackets, etc. from address strings?

arun smartpink111 at yahoo.com
Tue May 22 17:42:57 CEST 2012


Hi,

 text <- "[Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA"


 gsub("\\[.+?]","",text)
A.K.



----- Original Message -----
From: Sabina Arndt <sabina.arndt at hotmail.de>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, May 22, 2012 6:08 AM
Subject: [R] How to remove square brackets, etc. from address strings?


Hello,



I'd like to remove the individual pairs of square brackets along with 
their content - plus the space directly behind it - from address strings
such as this:


  [Swidsinski, Alexander; Loening-Baucke, Vera; Lochs, Herbert] Charite 
Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; [Hale, Laura P.] 
Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA



I'd like get the following result:



  Charite Humboldt Univ, Innere Klin, D-10098 Berlin, Germany; Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA



I tried


  address = gsub("(.*)[(.*)]", "\\2", address)



But this deletes everything from the first opening bracket to the last closing bracket and leaves only the very last address:


  Duke Univ, Med Ctr, Dept Pathol, Durham, NC 27710 USA



How can I remove only the individual pairs of square brackets along with their content?



Thank you very much in advance!                           
    [[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.




More information about the R-help mailing list