[R] Regular Expressions in grep

Dr. Holger van Lishaut H.v.Lishaut at gmx.de
Tue Aug 21 21:24:15 CEST 2012


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



More information about the R-help mailing list