Re: [R] Help with regular expressions.

2021-02-08 Thread Rolf Turner
On Tue, 9 Feb 2021 17:34:00 +1300 Rolf Turner wrote: > > David Wolfskill's post solved my problem perfectly. Thanks. > > Thanks also to Bert Gunter and Avi Gross. Whoops. David Wolfskill's message came to me off-list. Sorry for the confusion. cheers, Rolf -- Honorary Research Fellow De

Re: [R] Help with regular expressions.

2021-02-08 Thread Rolf Turner
David Wolfskill's post solved my problem perfectly. Thanks. Thanks also to Bert Gunter and Avi Gross. cheers, Rolf -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@r-project.or

Re: [R] Help with regular expressions.

2021-02-08 Thread Bert Gunter
Simpler, but would fail if there are more "."s beyond the second (it changes the last one to a "-"): > sub("(.*)\\.([^.]*)", "\\1-\\2", "aa.bcv.cdg") [1] "aa.bcv-cdg" Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Be

Re: [R] Help with regular expressions.

2021-02-08 Thread Avi Gross via R-help
first and second time starting just past it. Then replace. Fairly straightforward and very possibly much faster. -Original Message- From: R-help On Behalf Of Rolf Turner Sent: Monday, February 8, 2021 9:29 PM To: "r-help@R-project.org" "@r-project.org Subject: [R] Help with regul

Re: [R] Help with regular expressions.

2021-02-08 Thread Bert Gunter
> gsub("(.*\\.[^.]*)\\.(.*)","\\1-\\2", "aa.bcv.cdg") [1] "aa.bcv-cdg" Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Feb 8, 2021 at 6:29 PM

[R] Help with regular expressions.

2021-02-08 Thread Rolf Turner
I want to deal with strings of the form "a.b.c" and to change (using sub() or whatever is appropriate) the second "." to a "-", i.e. to change "a.b.c" to "a.b-c". I want to leave the first "." as-is. I guess I could do a gsub(), changing all "."s to "-"s, and then do a sub() changing the first

Re: [R] Help with regular expressions

2018-02-12 Thread Ulrik Stervbo
I think I would replace all , with . and subsequently replace all first . with , using ^\\. x <- gsub(",", ".", x) gsub("^\\.", ",", x) It's not so elegant, but it is easier to understand than backreferences and complex regex. Best, Ulrik On Tue, 13 Feb 2018, 03:38 Boris Steipe, wrote: > You

Re: [R] Help with regular expressions

2018-02-12 Thread Boris Steipe
You can either use positive lookahead/lookbehind - but support for that is a bit flaky. Or write a proper regex, and use backreferences to keep what you need. R > x <- "abc 1,1 ,1 1, x,y 2,3 " R > gsub("(\\d),(\\d)", "\\1.\\2", x, perl = TRUE) [1] "abc 1.1 ,1 1, x,y 2.3 " B. > On Feb 12, 20

Re: [R] Help with regular expressions

2018-02-12 Thread David Winsemius
> On Feb 12, 2018, at 6:22 PM, Dennis Fisher wrote: > > R 3.4.2 > OS X > > Colleagues > > I would appreciate some help with regular expressions. > > I have string that looks like: > " ITERATION ,THETA1 ,THETA2 > ,THETA3 ,THET

Re: [R] Help with regular expressions

2018-02-12 Thread Jim Lemon
Hi Dennis, How about: # define the two values to search for x<-2 y<-3 # create your search string and replacement string repstring<-paste(x,y,sep=",") newstring<-paste(x,y,sep=".") # this is the string that you want to change thetastring<-"SIGMA(2,3)" sub(repstring,newstring,thetastring) [1] "SIG

[R] Help with regular expressions

2018-02-12 Thread Dennis Fisher
R 3.4.2 OS X Colleagues I would appreciate some help with regular expressions. I have string that looks like: " ITERATION ,THETA1 ,THETA2 ,THETA3 ,THETA4 ,THETA5 ,THETA6 ,THETA7

Re: [R] help with regular expressions in R

2009-08-20 Thread Mark Kimpel
------ >> Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry >> Indiana University School of Medicine >> >> 15032 Hunter Court, Westfield, IN 46074 >> >> (317) 490-5129 Work, & Mobile & VoiceMail

Re: [R] help with regular expressions in R

2009-08-20 Thread William Dunlap
2009 9:28 AM To: William Dunlap; r-help@r-project.org Subject: Re: [R] help with regular expressions in R Well, I guess I'm not quite there yet. What I gave earlier was a simplified example, and did not accurately reflect the complexity of the task.

Re: [R] help with regular expressions in R

2009-08-20 Thread Mark Kimpel
*** On Thu, Aug 20, 2009 at 11:39 AM, William Dunlap wrote: > > > -----Original Message- > > From: r-help-boun...@r-project.org > > [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Kimpel > > Sent: Thursday, August 20, 2009 8:31

Re: [R] help with regular expressions in R

2009-08-20 Thread Chuck Taylor
Mark, Try this: > myCharVec [1] "[the rain in spain]" "(the rain in spain)" > gsub("\\[.*\\]", "", myCharVec) [1] """(the rain in spain)" You need two backslashes to "escape" the square brackets. The regular expression "\\[.\\]" translates to "a [ followed by 0 or more insta

Re: [R] help with regular expressions in R

2009-08-20 Thread jim holtman
How about this: > myCharVec <- c("[the rain in spain]", "(the rain in spain)") > gsub('\\[.*\\]', '', myCharVec) [1] """(the rain in spain)" > you had "*." when you should have ".*" On Thu, Aug 20, 2009 at 11:30 AM, Mark Kimpel wrote: > I'm having trouble achieving the resul

[R] help with regular expressions in R

2009-08-20 Thread Mark Kimpel
I'm having trouble achieving the results I want using a regular expression. I want to eliminate all characters that fall within square brackets as well as the brackets themselves, returning an "". I'm not sure if it's R's use of double slash escapes or something else that is tripping me up. If I on