Here is one way of doing it: > MyData <- c("Test1","Test2","I(Test1^2)","I(Test2^3)","I(Test1.Test2^2)") > x <- gsub("^(.*\\(|)([^^)]*|.*).*", "\\2", MyData) > x [1] "Test1" "Test2" "Test1" "Test2" "Test1.Test2" > unique(x) [1] "Test1" "Test2" "Test1.Test2" >
On Feb 12, 2008 5:44 AM, Tom.O <[EMAIL PROTECTED]> wrote: > > Hi > > I have this vector of strings. > > MyData <- c("Test1","Test2","I(Test1^2)","I(Test2^3)","I(Test1.Test2^2)") > where I want to extract only the text after "I(" and before "^" so that the > string returned only contain c("Test1","Test2","Test1.Test2") > > I am not very skilled in the use of matching patterns so bare with me but I > belive I should use gsub('^.\\(', "",MyData) for removing the "I(" and > gsub("\\^.+", '',MyData) for the end. but theres got to be a more elegant > way that does the trick in one go. > > So I would appriciate I anyone could give me some advice. > > Thanks Tom > -- > View this message in context: > http://www.nabble.com/Matching-Problem-tp15430660p15430660.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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 Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ 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.