[R] yet another regular expression

Duncan Mackay dulcalma at bigpond.com
Mon Jun 30 16:15:49 CEST 2014

Hi Jim

What about trying to use what you want to keep

m=gregexpr('\\":value[12]+[}]?,', initString)
regmatches(initString, m)
[1] "\":value1,"  "\":value2},"


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Jim Lemon
Sent: Monday, 30 June 2014 23:13
To: r-help at r-project.org
Subject: [R] yet another regular expression

Hi all,
I have managed, with the help of glob2rx() to get two parts of a text 
manipulation working. I have successfully gotten rid of the first and 
second bits, but I have hit the wall trying to get rid of the last bit.
an example:

 "\"Delete this\":value1,\"Delete this too\":value2},Delete last bit"
sub("\"Delete this too\":","",

This gives me:

[1] "value1,value2},Delete last bit"

and glob2rx("},*") just won't get rid of the last bit. I throw myself upon 
the mercy of the regular expression gurus.


R-help at r-project.org mailing list
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