Skip to content
Prev 277275 / 398506 Next

regular expression for selection

Hi

Thank you. It is a pure magic, something taught in Unseen University.

this is what I got as a help for selecting only letters from set of 
character vector.
[1] "61A"     "62C/27"  "65A/27"  "66C/29"  "69A/29"  "70C/31"
"73A/31" 
 [8] "74C/33"  "77A/33"  "81A/35"  "82C/37"  "85A/37"  "86C/39"
"89A/39" 
[15] "90C/41"  "93A/41"  "94C/43"  "97A/43"  "98C/45"  "101A/45"
"102C/47"
[22] "105A/47" "106C/49" "109A/49" "110C/51" "113A/51"
[1] "A" "C" "A" "C" "A" "C" "A" "C" "A" "A" "C" "A" "C" "A" "C" "A" "C"
[18] "A" "C" "A" "C" "A" "C" "A" "C" "A"

Therefore I expected that

sub("m5.", "\\1", mena) or sub("m5.", "", mena)

selects what I wanted. But it was not the case.

Please can you correct me when I try to evaluate your solution?

gsub(".*_(m5.).*", "\\1", mena)

or

gsub(".*(m5.).*", "\\1", mena)

.* matches any characters
() negation? or matching selection for back reference?

Finally the expressin matches whole string and evaluates what is matched 
by parenthesised value. This evaluation is returned by backreference.

Is it correct evaluation?

Regards
Petr
my
http://www.R-project.org/posting-guide.html