[R] regular expression help

Philippe Grosjean phgrosjean at sciviews.org
Wed Apr 18 09:04:17 CEST 2007


gsub("^.*([[:alpha:]]).*$", "\\1", vzor)


..............................................<°}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..............................................................

Petr PIKAL wrote:
> Dear all
> 
> as usual I am again lost in virtues of regular expressions.
> 
> I have such character vector named vzor:
> 
> [365] "61A"      "62C/27"   "65A/27"   "66C/29"   "69A/29"   "70C/31" 
> "73A/31"   "74C/33"   "77A/33"   "81A/35"   "82C/37"   "85A/37"   "86C/39" 
>  
> [378] "89A/39"   "90C/41"   "93A/41"   "94C/43"   "97A/43"   "98C/45" 
> "101A/45"  "102C/47"  "105A/47"  "106C/49"  "109A/49"  "110C/51" "113A/51" 
> 
> 
> and I want only letters from it.
> 
> I tried
> 
>> gsub("[[:alpha:]]"," \\1",vzor)
> Error in gsub("[[:alpha:]]", " \\1", vzor) : 
>         invalid backreference 1 in regular expression
> 
> gsub("[:alpha:]"," \\1",vzor)
> 
> gives me the same vector
> 
> There is probably very simple solution to it which I overlooked and 
> examples in help page did not help me to find it.
> 
> Thank you
> Best regards
> 
> Petr Pikal
> petr.pikal at precheza.cz
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list