Hi, search in web for regular expressions i get the information that the line below replace all AUTO string's like AUTOBAHN ,AUTORENNEN with 1 but nothing happend. Using the [] in the pattern it works like i'm expected, but i didn't want single character replacment. Where is my mistake? bcode <- gsub("/^AUTO.*/","1",MyStringVector,ignore.case=T,extended=T) many thanks & regards, christian
Christian Schulz wrote:> Where is my mistake? > > bcode <- gsub("/^AUTO.*/","1",MyStringVector,ignore.case=T,extended=T) >You dont need the slashes! You've been looking at documentation for Perl regular expression replacements, I guess. help(gsub) may have showed you the way. Here's how to do it: > MyStringVector=c("AUTOBAHN","NAUTON","FOO","AUTOGRAPH") # wrong way: > gsub("/^AUTO.*/","1",MyStringVector,ignore.case=T,extended=T) [1] "AUTOBAHN" "NAUTON" "FOO" "AUTOGRAPH" # dont slash all over the regexp: > gsub("^AUTO.*","1",MyStringVector,ignore.case=T,extended=T) [1] "1" "NAUTON" "FOO" "1" Is that what you're after? Baz
Christian Schulz <ozric at web.de> writes:> Hi, > > search in web for regular expressions i get the information that > the line below replace all AUTO string's like AUTOBAHN > ,AUTORENNEN with 1 but nothing happend. > Using the [] in the pattern it works like i'm expected, but i didn't > want single character replacment. Where is my mistake? > > bcode <- gsub("/^AUTO.*/","1",MyStringVector,ignore.case=T,extended=T)What are the "/"-es for? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907