> test <- c("pH 9,36 2", "pH 9,36 3", "pH 9,66 1", "pH 9,66 2", "pH 9,66 3",
+ "pH 10,04 1", "pH 10,04 2", "pH 10,04 3", "RGLP 144006 pH 6,13 1",
+ "RGLP 144006 pH 6,13 2", "RGLP 144006 pH 6,13 3")
>
> # make it less greedy with a "?"
> gsub("^.*?([[:digit:]]+,[[:digit:]]*).*$", "\\1", test)
 [1] "9,36"  "9,36"  "9,66"  "9,66"  "9,66"  "10,04" "10,04" "10,04" "6,13"
 "6,13"  "6,13"
>



On Tue, Jul 9, 2013 at 8:05 AM, arun <smartpink111@yahoo.com> wrote:

> Hi,
> May be this helps:
>
>   gsub(".*\\w+\\s+(.*)\\s+.*","\\1",test)
>  #[1] "9,36"  "9,36"  "9,66"  "9,66"  "9,66"  "10,04" "10,04" "10,04"
> "6,13"
> #[10] "6,13"  "6,13"
>
> A.K.
>
> ----- Original Message -----
> From: PIKAL Petr <petr.pikal@precheza.cz>
> To: r-help <r-help@r-project.org>
> Cc:
> Sent: Tuesday, July 9, 2013 5:45 AM
> Subject: [R] regular expression strikes again
>
> Dear experts in regexpr.
>
> I have this
>
> dput(test[500:510])
> c("pH 9,36 2", "pH 9,36 3", "pH 9,66 1", "pH 9,66 2", "pH 9,66 3",
> "pH 10,04 1", "pH 10,04 2", "pH 10,04 3", "RGLP 144006 pH 6,13 1",
> "RGLP 144006 pH 6,13 2", "RGLP 144006 pH 6,13 3")
>
> and I want something like this
>
> gsub("^.*([[:digit:]],[[:digit:]]*).*$", "\\1", test[500:510])
> [1] "9,36" "9,36" "9,66" "9,66" "9,66" "0,04" "0,04" "0,04" "6,13" "6,13"
> [11] "6,13"
>
> but with 10,04 values instead of 0,04.
>
> I tried
> gsub("^.*([[:digit:]]+,[[:digit:]]*).*$", "\\1", test[500:510])
>
> or other variations but without any success.
>
> Please help.
>
> Regards
> Petr
>
> ______________________________________________
> R-help@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.
>
>
> ______________________________________________
> R-help@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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

	[[alternative HTML version deleted]]

