Re: [R] Regex Question: return digits after particular letters

2011-06-02 Thread David Winsemius
On Jun 2, 2011, at 4:21 PM, Ben Ganzfried wrote: > Thank you very much for your help. It saved me a lot of time and it > worked perfectly. I have a quick follow-up as I'm not sure I > understand yet why the code works and where it comes from. > > For example, in: Tstg <- sub(".*T(\\d)N.", "

Re: [R] Regex Question: return digits after particular letters

2011-06-02 Thread Ben Ganzfried
Thank you very much for your help. It saved me a lot of time and it worked perfectly. I have a quick follow-up as I'm not sure I understand yet why the code works and where it comes from. For example, in: Tstg <- sub(".*T(\\d)N.", "\\1", tmp) *How exactly does the substitution operation work?

Re: [R] Regex Question: return digits after particular letters

2011-06-02 Thread David Winsemius
On Jun 2, 2011, at 2:54 PM, Ben Ganzfried wrote: Hi, First of all, I would like to introduce myself as I will probably have many questions over the next few weeks and want to thank you guys in advance for your help. I'm a cancer researcher and I need to learn R to complete a few projec

Re: [R] regex question on escaping "." (and a couple other regex questions as well)

2010-01-07 Thread David Winsemius
On Jan 7, 2010, at 2:47 PM, Mark Kimpel wrote: I have an example where escaping "." does not seem to be behaving consistently, but perhaps it is due to my misunderstanding. Could someone explain to me why the below produces the output it does? It seems to me that in the second example, wher

[R] regex question on escaping "." (and a couple other regex questions as well)

2010-01-07 Thread Mark Kimpel
I have an example where escaping "." does not seem to be behaving consistently, but perhaps it is due to my misunderstanding. Could someone explain to me why the below produces the output it does? It seems to me that in the second example, where I am being more precise about specifying that a "."

Re: [R] regex question

2009-08-04 Thread Michael Erickson
Here's what I came up with: > gsub("(\\w)[^ ]+[\\b ]", "\\1", astr) [1] "Timtowtdit" You might be interested in Regular Expressions Cookbook from O'Reilly (publisher not author) or http://www.regular-expressions.info/ I usually bumble along knowing there are better ways to do whatever I am doing

Re: [R] regex question

2009-08-04 Thread Chuck Taylor
ult can be used to subscript avec. Best regards, Chuck Taylor TIBCO Spotfire Seattle, WA, USA -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ravi Sent: Tuesday, August 04, 2009 10:28 AM To: r-help@r-project.org Subject: [R] regex

Re: [R] regex question

2009-08-04 Thread Gabor Grothendieck
And here is a second way: > strapply(astr, "(\\w)\\w+", c, simplify = c) [1] "T" "i" "m" "t" "o" "w" "t" "d" "i" "i" "t" "f" "f" "T" On Tue, Aug 4, 2009 at 1:42 PM, Gabor Grothendieck wrote: > Try this: > >> library(gsubfn) >> strapply(astr, "\\w+", ~ substr(x, 1, 1), simplify = c) >  [1] "T" "

Re: [R] regex question

2009-08-04 Thread Gabor Grothendieck
Try this: > library(gsubfn) > strapply(astr, "\\w+", ~ substr(x, 1, 1), simplify = c) [1] "T" "i" "m" "t" "o" "w" "t" "d" "i" "i" "t" "f" "f" "T" On Tue, Aug 4, 2009 at 1:28 PM, ravi wrote: > > Hi, > I am getting stuck over an apparently simple problem in the use of regular > expressions : > T

[R] regex question

2009-08-04 Thread ravi
Hi, I am getting stuck over an apparently simple problem in the use of regular expressions : To collect together the first letters of the words from the Perl motto, “There is more than one way to do it” in the following form – TIMTOWTDI. I tried the following code :   # A regex problem with

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Tan, Richard wrote: > Sorry I did not give some examples in my previous posting to make my > question clear. It's not exactly 1 digit, but at least one digit. Here > are some examples: > > >> input = c(none='0foo f0oo foo0 foofoofoo0 0foofoofoo TOOL9NGG >> > NONUMBER',all='foob0 fo0o0

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Tan, Richard
e- From: Wacek Kusnierczyk [mailto:waclaw.marcin.kusnierc...@idi.ntnu.no] Sent: Tuesday, June 09, 2009 1:06 PM To: Greg Snow Cc: Marc Schwartz; Barry Rowlingson; r-help@r-project.org; Tan, Richard Subject: Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Greg Snow wrote: > Here is one way using a single pattern (so can be used in a substitution), it > uses Perl's positive look ahead patters: > > >> test <- >> c("SHRT","5HRT","M1TCH","M1TCH5","LONG3RS","NONUMBER","TOOLNGG","ooops.3") >> >> sub( '(?=[a-zA-Z]{0,8}[0-9])[a-zA-Z0-9]{5,9}', 'xxx

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Greg Snow
ps.3" > -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Marc Schwartz > Sent: Monday, J

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: > Marc Schwartz wrote: > >> On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote: >> >> >>> On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote: >>> Hi, This is not exactly an R question but I am trying to use gsub to replace a string t

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Wacek Kusnierczyk
Marc Schwartz wrote: > > On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote: > >> On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote: >>> Hi, >>> >>> This is not exactly an R question but I am trying to use gsub to >>> replace >>> a string that contains 5-9 alpha-numeric characters, at least one o

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-08 Thread Marc Schwartz
On Jun 8, 2009, at 5:27 PM, Barry Rowlingson wrote: On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote: Hi, This is not exactly an R question but I am trying to use gsub to replace a string that contains 5-9 alpha-numeric characters, at least one of which is a number. Is there a good wa

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-08 Thread Barry Rowlingson
On Mon, Jun 8, 2009 at 10:40 PM, Tan, Richard wrote: > Hi, > > This is not exactly an R question but I am trying to use gsub to replace > a string that contains 5-9 alpha-numeric characters, at least one of > which is a number.  Is there a good way to write it in a one line regex? The only way I

[R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-08 Thread Tan, Richard
Hi, This is not exactly an R question but I am trying to use gsub to replace a string that contains 5-9 alpha-numeric characters, at least one of which is a number. Is there a good way to write it in a one line regex? Thanks, Richard __ R-help@r-proj

Re: [R] regex question

2008-11-04 Thread Peter Dalgaard
[EMAIL PROTECTED] wrote: Hi: Gabor's solution does do it in a single line. he just used paste to make the line. see below. John's is sort of a single line also but he called sub twice. I doubt that it's possible to make it shorter than those solutions. Well, you can lose the parentheses and

Re: [R] regex question

2008-11-03 Thread markleeds
; ]+$)" sub(right, "", sub(left, "", varReg)) [1] "this is my text" I hope this helps, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Mess

Re: [R] regex question

2008-11-03 Thread Ferry
-- > John Fox, Professor > Department of Sociology > McMaster University > Hamilton, Ontario, Canada > web: socserv.mcmaster.ca/jfox > > >> -Original Message- >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On >> Behalf Of Ferry >&g

Re: [R] regex question

2008-11-03 Thread John Fox
uot;this is my text" I hope this helps, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Be

Re: [R] regex question

2008-11-03 Thread Gabor Grothendieck
If patReg1 and patReg2 are your two regex's then: gsub(paste(patReg1, patReg2, sep = "|"), "", varReg) On Mon, Nov 3, 2008 at 8:37 PM, Ferry <[EMAIL PROTECTED]> wrote: > hello, > > i am trying to extract text using regex as follows: > > "* < <* this is my text > > " > > into: > > "this is my

[R] regex question

2008-11-03 Thread Ferry
hello, i am trying to extract text using regex as follows: "* < <* this is my text > > " into: "this is my text" below what I did: varReg <- "* < <* this is my text > > " ## either this pattern patReg <- "(^[ <*]+)" ## or below patten patReg <- "([ > ]+$)" sub(patReg, '', varReg) dependi