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

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 __

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

Re: [R] Help with regular expressions.

2021-02-08 Thread Avi Gross via R-help
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 regular express

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

[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,

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,

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 >

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]

[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

[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

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 Kimpelmwkim...@gmail.com wrote: I'm having trouble achieving the

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 instances of any

Re: [R] help with regular expressions in R

2009-08-20 Thread Mark Kimpel
: Thursday, August 20, 2009 8:31 AM To: r-help@r-project.org Subject: [R] help with regular expressions in R ... myCharVec - c([the rain in spain], (the rain in spain)) gsub('\\[*.\\]', '', myCharVec) Change the '*.' to '.*'. Your expression matches 0 or more left square brackets

Re: [R] help with regular expressions in R

2009-08-20 Thread William Dunlap
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. This is my real world example. As you can see, what I need

Re: [R] help with regular expressions in R

2009-08-20 Thread Mark Kimpel
-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Kimpel Sent: Thursday, August 20, 2009 8:31 AM To: r-help@r-project.org Subject: [R] help with regular expressions in R ... myCharVec - c([the rain in spain], (the rain in spain)) gsub('\\[*.\\]', '', myCharVec