I have a string like this st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), COUNT(salary), FROM Employees" How can I remove the last comma before the FROM statement? -J
Try this: gsub(",\\s+FROM", " FROM", st) On Wed, May 4, 2011 at 4:41 PM, johannes rara <johannesraja at gmail.com> wrote:> I have a string like this > > st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), > COUNT(salary), FROM Employees" > > How can I remove the last comma before the FROM statement? > > -J > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On Wed, 2011-05-04 at 22:41 +0300, johannes rara wrote:> I have a string like this > > st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), > COUNT(salary), FROM Employees" > > How can I remove the last comma before the FROM statement?gsub(",[^,]*FROM ", " FROM ", st) HTH, Jerome
On Wed, May 04, 2011 at 10:41:36PM +0300, johannes rara wrote:> I have a string like this > > st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), > COUNT(salary), FROM Employees" > > How can I remove the last comma before the FROM statement?This doesn't use a regex, per se, but:> st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), COUNT(salary), FROM Employees" > st[1] "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), COUNT(salary), FROM Employees"> sub(", FROM", " FROM", st)[1] "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname), COUNT(salary) FROM Employees">I'm not sure that's what you had in mind, though. Peace, david -- David H. Wolfskill r at catwhisker.org Depriving a girl or boy of an opportunity for education is evil. See http://www.catwhisker.org/~david/publickey.gpg for my public key. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110504/4c646255/attachment.bin>