[R] Regular Expressions in grep

Bert Gunter gunter.berton at gene.com
Tue Aug 21 21:37:57 CEST 2012


grep() returns the matches. You want regexpr() and regmatches()

-- Bert

On Tue, Aug 21, 2012 at 12:24 PM, Dr. Holger van Lishaut
<H.v.Lishaut at gmx.de> wrote:
> Dear r-help members,
>
> I have a number in the form of a string, say:
>
> a<-"-01020.909200"
>
> I'd like to extract "1020." as well as ".9092"
>
> Front<-grep(pattern="[1-9]+[0-9]*\\.", value=TRUE, x=a, fixed=FALSE)
> End<-grep(pattern="\\.[0-9]*[1-9]+", value=TRUE, x=a, fixed=FALSE)
>
> However, both strings give "-01020.909200", exactly a.
> Could you please point me to what is wrong?
>
> Thanks and best regards
> H. van Lishaut
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm




More information about the R-help mailing list