regex - Extract a regular expression match in R version 2.10 -
I am trying to extract a number from a string.
And do something like [0-9] + Get "aaa1212xx" and "12" on this string.
I thought that something like this would happen:
& gt; Grep ("[0-9] +", "aaa12xxx", value = TRUE) [1] "aaa12xxx"
And then I thought ...
& gt; Sub ("[0- 9] +", "\\ 1", "aaa12xxxx") [1] "AAA 121xxx"
But I got some sort of response:
& gt; Sub ("[0-9] +", "ARG!", "AAA 12xxxx") [1] "AAAAH! Xxx"
I have a little information missing, please Advice: -)
I am using R Version 2.10.1 (2009-12-14)
Thanks!
The best solution is to get something to understand the package really. / P>
Use the new Stringer package, which contains all existing regular expressions in a consistent syntax Operates and adds some that are missing:
Library (stringer) str_locate ("aaa12xxx", "[0-9] +") # Getting started # [1,] 4 5 Strawaktrack ("AAA 12xxx", "[0-9] +") # [1] "12"
Comments
Post a Comment