Re: [R] extracting values from txt with regular expression

2012-06-08 Thread Gabor Grothendieck
On Thu, Jun 7, 2012 at 1:40 PM, emorway wrote: > Thanks for your suggestions.  Bert, in your response you raised my awareness > to "regular expressions".  Are regular expressions the same across various > languages?  Consider the following line of text: > > txt_line<-" PERCENT DISCREPANCY =      

Re: [R] extracting values from txt with regular expression

2012-06-08 Thread Rui Barradas
Hello, Just put the entire regexp between parenthesis. extracted <- strsplit(gsub("([+-]?(?:\\d+(?:\\.\\d*)|\\.\\d+)(?:[eE][+-]?\\d+)?)","\\1%&",txt_line),"%&") extracted sapply(strsplit(unlist(extracted), "="), "[", 2) As for speed, I believe that this might take longer. It will have to

Re: [R] extracting values from txt with regular expression

2012-06-07 Thread emorway
Hi Dan and Rui, Thank you for the suggestions, both were very helpful. Rui's code was quite fast...there is one more thing I want to explore for my own edification, but first I need some help fixing the code below, which is a slight modification to Dan's suggestion. It'll no doubt be tough to be

Re: [R] extracting values from txt with regular expression

2012-06-07 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of emorway > Sent: Thursday, June 07, 2012 10:41 AM > To: r-help@r-project.org > Subject: [R] extracting values from txt with regular expression > > Thanks for your suggestions. Be